-
Notifications
You must be signed in to change notification settings - Fork 2
/
codeforcesD.cpp
59 lines (47 loc) · 917 Bytes
/
codeforcesD.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve(){
int n;
cin >> n;
vector<int> spend(n);
vector<int> budget(n);
// int a;
for(int i = 0; i < n; i++){
cin >> spend[i];
}
for(int i = 0; i < n; i++){
cin >> budget[i];
}
vector<int> surplus;
for(int i = 0; i < n; i++){
surplus.push_back(budget[i]-spend[i]);
}
sort(surplus.begin(), surplus.end());
int i = 0;
int j = n-1;
int grp = 0;
while(i < j){
if(surplus[j] + surplus[i] >= 0){
grp++;
i++;
j--;
}
else{
i++;
}
}
cout << grp << endl;
}
int main(){
// #ifndef MYNK
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int t;
cin >> t;
while(t--){
solve();
}
return 0;
}