-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCF Round 733 - Pursuit (C).cpp
82 lines (74 loc) · 1.77 KB
/
CF Round 733 - Pursuit (C).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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Problem Link: https://codeforces.com/contest/1530/problem/C
#include<iostream>
#include<limits.h>
#include<math.h>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<algorithm>
using namespace std;
#define ll long long
#define ull unsigned long long
#define modulo 1000000007
#define mp make_pair
#define pb push_back
bool is_valid(int n, int m, int x, int y)
{
return (x >= 0 && x < n && y >= 0 && y < m);
}
int main()
{
ll int tests;
cin >> tests;
while(tests--)
{
ll int n;
cin >> n;
vector<int> a(n), b(n);
for(auto i = 0; i < n; i++) {cin >> a[i];}
for(auto i = 0; i < n; i++) {cin >> b[i];}
sort(begin(a),end(a),greater<int>());
sort(begin(b),end(b),greater<int>());
int stages = n - (n/4);
ll int mysum = 0, tarsum = 0;
int i = 0, j = 0;
for(; i < stages; i++, j++)
{
mysum += a[i];
tarsum += b[j];
}
if(mysum > tarsum) {cout << 0 << "\n"; continue;}
i--;
j--;
int ctr = n%4;
int ans = 0;
while(mysum < tarsum)
{
if(ctr < 3)
{
mysum += 100;
if(j < n-1) {j++; tarsum += b[j];}
ctr++;
}
else if(ctr == 3)
{
if(i >= 0)
{
mysum -= a[i];
i--;
mysum += 100;
}
ctr = 0;
}
ans++;
}
cout << ans;
cout << "\n";
}
return 0;
}