-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathe.cc
More file actions
55 lines (52 loc) · 1.31 KB
/
e.cc
File metadata and controls
55 lines (52 loc) · 1.31 KB
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
// https://codeforces.com/contest/1148/problem/E
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = tuple<ll, ll>;
using iii = tuple<ll, ll, ll>;
using vii = vector<ii>;
using viii = vector<iii>;
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
ll n, x = 0, y = 0, z, a = 0, b = 0;
cin >> n;
vii s(n), t(n);
for (int i = 0; i < n; i++) {
cin >> z;
s[i] = {z, i + 1};
a += z;
}
for (int i = 0; i < n; i++) {
cin >> z;
t[i] = {z, i + 1};
b += z;
}
sort(s.begin(), s.end());
sort(t.begin(), t.end());
if (a != b) {
cout << "NO\n";
return 0;
}
while (get<0>(s[x]) >= get<0>(t[x])) x++;
while (get<0>(s[y]) <= get<0>(t[y])) y++;
viii r;
while (x < n && y < n) {
if (x > y) {
cout << "NO\n";
return 0;
}
z = min(get<0>(t[x]) - get<0>(s[x]), get<0>(s[y]) - get<0>(t[y]));
if (get<0>(s[x]) > get<0>(s[y])) r.push_back({get<1>(s[y]), get<1>(s[x]), z});
else r.push_back({get<1>(s[x]), get<1>(s[y]), z});
get<0>(s[x]) += z;
get<0>(s[y]) -= z;
while (x < n && y < n && get<0>(s[y]) <= get<0>(t[y])) y++;
while (x < n && y < n && get<0>(s[x]) >= get<0>(t[x])) x++;
}
cout << "YES\n" << r.size() << "\n";
for (iii q : r) {
tie(x, y, z) = q;
cout << x << " " << y << " " << z << endl;
}
}