Chef and Races Problem Code: CHEFRACESSubmit (Practice)
The National Championships are starting soon. There are race categories, numbered from to , that Chef is interested in. Chef is participating in exactly of these categories.
Chef has an arch-rival who is, unfortunately, the only person participating who is better than Chef, i.e, Chef can't defeat the arch-rival in any of the four race categories but can defeat anyone else. Chef's arch-rival is also participating in exactly of the four categories.
Chef hopes to not fall into the same categories as that of the arch-rival.
Given where are the races that Chef participates in, and are the races that Chef's arch-rival participates in, find the maximum number of gold medals (first place) that Chef can win.
Input Format
- The first line of input contains an integer , denoting the number of testcases. The description of testcases follows.
- Each testcase consists of a single line containing four space-separated integers — the values of , and respectively.
Output Format
- For each testcase, print a single line containing one integer — the maximum number of gold medals that Chef can win.
Constraints
Subtasks
Subtask #1 (100 points): Original constraints
Sample Input 1
3
4 3 1 2
4 2 1 2
2 1 1 2
Sample Output 1
2
1
0
Explanation
Test case : Chef participates in the races , whereas Chef's rival participates in . As Chef's only rival does not participate in any of the races that Chef takes part in, Chef can win the gold medal in both of the races, thus the answer is .
Test case : Chef participates in the races , whereas Chef's rival participates in . Chef cannot win race as Chef will be beaten by the arch-rival, however Chef can win the gold medal for race . Thus the answer is .
Test case : Chef participates in the races , whereas Chef's rival participates in . Chef will be beaten by the arch-rival in both races, thus the answer is .
solution:
#include<iostream>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
void solve()
{
vector<ll> v(4);
for (int i = 0; i < 4; i++)
{
cin >> v[i];
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
ll n = v.size();
if (n == 4)
cout << n / 2 << "\n";
else
cout << (n - 1) / 2 << "\n";
}
int main()
{
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
No comments:
Post a Comment