-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB_Crafting.cpp
More file actions
48 lines (39 loc) · 940 Bytes
/
B_Crafting.cpp
File metadata and controls
48 lines (39 loc) · 940 Bytes
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
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int n;
cin >> n;
vector<int> a(n), b(n);
int total_a = 0, total_b = 0;
int mismatch_count = 0, need = 0, surplus = INT_MAX;
for (int i = 0; i < n; i++) {
cin >> a[i];
total_a += a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
total_b += b[i];
if (b[i] > a[i]) {
mismatch_count++;
need = max(need, b[i] - a[i]); // Track the largest deficit
} else {
surplus = min(surplus, a[i] - b[i]); // Track the smallest surplus
}
}
// Check conditions
if (mismatch_count > 1 || total_b > total_a || need > surplus) {
cout << "NO\n";
} else {
cout << "YES\n";
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
}