#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
int main(void){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n;
cin>>n;
ll b[n],p[n],u[n];
ll b2[n];
f(i,0,n){
cin>>b[i];
b2[i] = b[i];
}
f(i,0,n-1){
cin>>p[i];
}
f(i,0,n-1){
cin>>u[i];
}
bool ok = 1;
f(i,0,n-1){
ll posoi = max(0LL,p[i] - u[i]);
ll vale = min(posoi,b2[i]);
b2[i] -= vale;
posoi -= vale;
b2[i+1] -= posoi;
if(b2[i+1] < 0){
ok = 0;
}
}
if(ok){
cout<<"YES\n";
vector<vector<ll> >a,um,c;
vector<ll> A,UM,C;
ll ans = 0;
ll neo[n] = {0};
ll arxiko[n];
f(i,0,n){
arxiko[i] = b[i];
}
f(i,0,n-1){
ll vale = max(0LL,min(p[i],b[i]));
p[i] -= vale;
b[i] -= vale;
A.pb(vale);
neo[i] += vale;
UM.pb(0);
C.pb(p[i]);
neo[i+1] += p[i];
b[i+1] -= p[i];
if(p[i] == 0){
a.pb(A);
um.pb(UM);
c.pb(C);
A.clear();
UM.clear();
C.clear();
}
}
if(!A.empty()){
a.pb(A);
um.pb(UM);
c.pb(C);
A.clear();
UM.clear();
C.clear();
}
ll pos = 1;
f(i,0,a.size()){
ll sum = 0;
ll pre = pos;
f(j,0,(ll)a[i].size()){
sum += max(0LL,neo[pos] - arxiko[pos]);
pos++;
}
ans += sum;
pos = pre;
f(j,0,(ll)a[i].size()){
ll posa = min({sum,u[pos-1],c[i][j]});
um[i][j] = posa;
c[i][j] -= posa;
sum -= posa;
pos++;
}
assert(sum == 0);
}
cout<<ans<<"\n";
f(i,0,a.size()){
f(j,0,(ll)a[i].size()){
cout<<a[i][j]<<" "<<um[i][j]<<" "<<c[i][j]<<"\n";
}
}
}
else{
cout<<"NO\n";
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:8:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | #define f(i,a,b) for(ll i = a;i < b;i++)
......
91 | f(i,0,a.size()){
| ~~~~~~~~~~~~
Main.cpp:91:9: note: in expansion of macro 'f'
91 | f(i,0,a.size()){
| ^
Main.cpp:8:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | #define f(i,a,b) for(ll i = a;i < b;i++)
......
110 | f(i,0,a.size()){
| ~~~~~~~~~~~~
Main.cpp:110:9: note: in expansion of macro 'f'
110 | f(i,0,a.size()){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
150 ms |
47224 KB |
Output is correct |
5 |
Correct |
177 ms |
53248 KB |
Output is correct |
6 |
Correct |
161 ms |
47188 KB |
Output is correct |
7 |
Correct |
178 ms |
53244 KB |
Output is correct |
8 |
Correct |
2 ms |
856 KB |
Output is correct |
9 |
Correct |
2 ms |
860 KB |
Output is correct |
10 |
Correct |
373 ms |
155056 KB |
Output is correct |
11 |
Correct |
323 ms |
117704 KB |
Output is correct |
12 |
Correct |
395 ms |
142780 KB |
Output is correct |
13 |
Correct |
514 ms |
248308 KB |
Output is correct |
14 |
Correct |
152 ms |
46424 KB |
Output is correct |
15 |
Correct |
363 ms |
115020 KB |
Output is correct |
16 |
Correct |
388 ms |
114416 KB |
Output is correct |
17 |
Correct |
365 ms |
114516 KB |
Output is correct |
18 |
Correct |
365 ms |
114408 KB |
Output is correct |
19 |
Correct |
358 ms |
114516 KB |
Output is correct |
20 |
Correct |
372 ms |
115376 KB |
Output is correct |
21 |
Correct |
471 ms |
118152 KB |
Output is correct |
22 |
Correct |
459 ms |
155160 KB |
Output is correct |
23 |
Correct |
371 ms |
116152 KB |
Output is correct |
24 |
Correct |
446 ms |
126732 KB |
Output is correct |
25 |
Correct |
203 ms |
53332 KB |
Output is correct |
26 |
Correct |
191 ms |
53320 KB |
Output is correct |
27 |
Correct |
361 ms |
115052 KB |
Output is correct |
28 |
Correct |
406 ms |
142868 KB |
Output is correct |
29 |
Correct |
386 ms |
137868 KB |
Output is correct |
30 |
Correct |
389 ms |
115440 KB |
Output is correct |
31 |
Correct |
423 ms |
132328 KB |
Output is correct |
32 |
Correct |
381 ms |
115176 KB |
Output is correct |
33 |
Correct |
193 ms |
53240 KB |
Output is correct |
34 |
Correct |
192 ms |
53332 KB |
Output is correct |
35 |
Correct |
197 ms |
53336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
150 ms |
47224 KB |
Output is correct |
5 |
Correct |
177 ms |
53248 KB |
Output is correct |
6 |
Correct |
161 ms |
47188 KB |
Output is correct |
7 |
Correct |
178 ms |
53244 KB |
Output is correct |
8 |
Correct |
2 ms |
856 KB |
Output is correct |
9 |
Correct |
2 ms |
860 KB |
Output is correct |
10 |
Correct |
373 ms |
155056 KB |
Output is correct |
11 |
Correct |
323 ms |
117704 KB |
Output is correct |
12 |
Correct |
395 ms |
142780 KB |
Output is correct |
13 |
Correct |
514 ms |
248308 KB |
Output is correct |
14 |
Correct |
152 ms |
46424 KB |
Output is correct |
15 |
Correct |
363 ms |
115020 KB |
Output is correct |
16 |
Correct |
388 ms |
114416 KB |
Output is correct |
17 |
Correct |
365 ms |
114516 KB |
Output is correct |
18 |
Correct |
365 ms |
114408 KB |
Output is correct |
19 |
Correct |
358 ms |
114516 KB |
Output is correct |
20 |
Correct |
372 ms |
115376 KB |
Output is correct |
21 |
Correct |
471 ms |
118152 KB |
Output is correct |
22 |
Correct |
459 ms |
155160 KB |
Output is correct |
23 |
Correct |
371 ms |
116152 KB |
Output is correct |
24 |
Correct |
446 ms |
126732 KB |
Output is correct |
25 |
Correct |
203 ms |
53332 KB |
Output is correct |
26 |
Correct |
191 ms |
53320 KB |
Output is correct |
27 |
Correct |
361 ms |
115052 KB |
Output is correct |
28 |
Correct |
406 ms |
142868 KB |
Output is correct |
29 |
Correct |
386 ms |
137868 KB |
Output is correct |
30 |
Correct |
389 ms |
115440 KB |
Output is correct |
31 |
Correct |
423 ms |
132328 KB |
Output is correct |
32 |
Correct |
381 ms |
115176 KB |
Output is correct |
33 |
Correct |
193 ms |
53240 KB |
Output is correct |
34 |
Correct |
192 ms |
53332 KB |
Output is correct |
35 |
Correct |
197 ms |
53336 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
38 |
Halted |
0 ms |
0 KB |
- |