USACO 2022 US Open Contest Bronze Division - Counting Liars#
Problem link: here
Solution Author: Stefan Dascalescu
Problem Solution#
We can brute force through each of the N relevant places and find the minimum number of people who are lying.
Source codes#
The source codes in C++ and Python can be seen below.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<pair<char, int> > vp(n+1);
for(int i = 1; i <= n; i++)
cin >> vp[i].first >> vp[i].second;
int ans = n;
for(int i = 1; i <= n; i++)
{
int oki = 0;
for(int j = 1; j <= n; j++)
{
if(vp[j].first == 'G' && vp[i].second < vp[j].second)
oki++;
if(vp[j].first == 'L' && vp[i].second > vp[j].second)
oki++;
}
ans = min(ans, oki);
}
cout << ans;
return 0;
}