competitive-programmingNov 30, 20211 min read
[Codeforces] 1611B. Team Composition: Programmers and Mathematicians Explained
Updated: Nov 30, 2021
Math
Available in:enko
#Problem
1611B. Team Composition: Programmers and Mathematicians
#Approach
Let the larger value be a and the smaller value be b.
Focus on .
Forming a team with a ratio is equivalent to subtracting 2 from this value.
Therefore, the maximum number of teams that can be formed with a ratio is .
Subtract this value from , and form teams with the remaining people () using a ratio.
#Code

/**
* written: 2021. 11. 30. Tue. 15:33:05 [UTC+9]
* jooncco의 mac에서.
**/
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(0),cin.tie(0)
int a,b;
void solve() {
cin >> a >> b;
if (a < b) swap(a,b);
int dif= abs(a-b);
int threeAndOne= dif/2;
int ans= min(threeAndOne,b) + (b-min(threeAndOne,b))/2;
cout << ans << "\n";
}
int main() {
FAST_IO;
int t; cin >> t;
while (t--) solve();
}
#Complexity
- Time:
- Space: