File tree 1 file changed +59
-0
lines changed
1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ using namespace std ;
3
+ typedef long long int ll;
4
+
5
+ void solve (){
6
+ int n;
7
+ cin >> n;
8
+
9
+ vector<int > spend (n);
10
+ vector<int > budget (n);
11
+ // int a;
12
+
13
+ for (int i = 0 ; i < n; i++){
14
+ cin >> spend[i];
15
+ }
16
+
17
+ for (int i = 0 ; i < n; i++){
18
+ cin >> budget[i];
19
+ }
20
+
21
+ vector<int > surplus;
22
+ for (int i = 0 ; i < n; i++){
23
+ surplus.push_back (budget[i]-spend[i]);
24
+ }
25
+
26
+ sort (surplus.begin (), surplus.end ());
27
+
28
+ int i = 0 ;
29
+ int j = n-1 ;
30
+
31
+ int grp = 0 ;
32
+
33
+ while (i < j){
34
+ if (surplus[j] + surplus[i] >= 0 ){
35
+ grp++;
36
+ i++;
37
+ j--;
38
+ }
39
+ else {
40
+ i++;
41
+ }
42
+ }
43
+
44
+ cout << grp << endl;
45
+ }
46
+
47
+ int main (){
48
+ // #ifndef MYNK
49
+ // freopen("input.txt", "r", stdin);
50
+ // freopen("output.txt", "w", stdout);
51
+ // #endif
52
+ int t;
53
+ cin >> t;
54
+ while (t--){
55
+ solve ();
56
+ }
57
+
58
+ return 0 ;
59
+ }
You can’t perform that action at this time.
0 commit comments