Submission #710951

# Submission time Handle Problem Language Result Execution time Memory
710951 2023-03-16T06:10:36 Z emptypringlescan Rainy Markets (CCO22_day1problem2) C++17
0 / 25
515 ms 80428 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	long long cap[n],pop[n-1],um[n-1];
	for(int i=0; i<n; i++) cin >> cap[i];
	for(int i=0; i<n-1; i++) cin >> pop[i];
	for(int i=0; i<n-1; i++) cin >> um[i];
	bool cant=false;
	long long left=cap[0];
	for(int i=0; i<n-1; i++){
		long long peep=pop[i]-left-um[i];
		left=cap[i+1]-peep;
		if(left<0) cant=true;
	}
	if(cant){
		cout << "NO";
		return 0;
	}
	long long fill[n],buy[n-1];
	memset(fill,0,sizeof(fill));
	memset(buy,0,sizeof(buy));
	for(int i=0; i<n-1; i++){
		long long space=cap[i]-fill[i],peep=pop[i];
		if(space>=pop[i]){
			fill[i]+=pop[i];
			continue;
		}
		fill[i]=cap[i];
		peep-=space;
		if(peep<=cap[i+1]){
			fill[i+1]=peep;
			continue;
		}
		fill[i+1]=cap[i+1];
		peep-=cap[i+1];
		buy[i]=peep;
	}
	long long sludge=0;
	for(int i=n-1; i>=0; i--){
		if(buy[i]>um[i]){
			sludge+=buy[i]-um[i];
			buy[i]=um[i];
		}
		if(buy[i]<um[i]){
			if(um[i]-buy[i]>=sludge){
				buy[i]+=sludge;
				sludge=0;
			}
			else{
				sludge-=um[i]-buy[i];
				buy[i]=um[i];
			}
		}
		assert(sludge<=cap[i]);
		sludge-=cap[i]-fill[i];
		sludge=max(sludge,0LL);
	}/*
	for(int i=0; i<n; i++) cout << fill[i] << ' ';
	cout << '\n';
	for(int i=0; i<n-1; i++) cout << buy[i] << ' ';
	cout << '\n';*/
	assert(sludge==0);
	cout << "YES\n";
	long long cost=0,space=cap[0];
	for(int i=0; i<n-1; i++) cost+=buy[i];
	cout << cost << '\n';
	for(int i=0; i<n-1; i++){
		if(space<=pop[i]) cout << space << ' ';
		else cout << pop[i] << ' ';
		cout << buy[i] << ' ';
		if(pop[i]-space-buy[i]>0){
			cout << pop[i]-space-buy[i] << '\n';
			space=cap[i+1]-(pop[i]-space-buy[i]);
		}
		else{
			cout << 0 << '\n';
			space=cap[i+1];
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 200 ms 24064 KB Output is correct
5 Correct 233 ms 24328 KB Output is correct
6 Correct 195 ms 24064 KB Output is correct
7 Correct 240 ms 24372 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 3 ms 588 KB Output is correct
10 Correct 408 ms 46032 KB Output is correct
11 Correct 353 ms 47504 KB Output is correct
12 Correct 481 ms 59820 KB Output is correct
13 Correct 484 ms 53932 KB Output is correct
14 Correct 198 ms 24072 KB Output is correct
15 Correct 492 ms 64468 KB Output is correct
16 Correct 456 ms 63264 KB Output is correct
17 Correct 474 ms 62468 KB Output is correct
18 Correct 511 ms 61856 KB Output is correct
19 Correct 470 ms 64536 KB Output is correct
20 Correct 457 ms 61740 KB Output is correct
21 Correct 488 ms 64416 KB Output is correct
22 Correct 473 ms 59116 KB Output is correct
23 Correct 454 ms 61988 KB Output is correct
24 Correct 515 ms 64020 KB Output is correct
25 Correct 248 ms 25220 KB Output is correct
26 Correct 266 ms 27420 KB Output is correct
27 Correct 497 ms 62140 KB Output is correct
28 Correct 466 ms 60472 KB Output is correct
29 Correct 446 ms 61756 KB Output is correct
30 Correct 482 ms 64780 KB Output is correct
31 Correct 484 ms 61776 KB Output is correct
32 Correct 458 ms 61972 KB Output is correct
33 Runtime error 296 ms 80428 KB Execution killed with signal 6
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Runtime error 2 ms 444 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Runtime error 2 ms 444 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 200 ms 24064 KB Output is correct
5 Correct 233 ms 24328 KB Output is correct
6 Correct 195 ms 24064 KB Output is correct
7 Correct 240 ms 24372 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 3 ms 588 KB Output is correct
10 Correct 408 ms 46032 KB Output is correct
11 Correct 353 ms 47504 KB Output is correct
12 Correct 481 ms 59820 KB Output is correct
13 Correct 484 ms 53932 KB Output is correct
14 Correct 198 ms 24072 KB Output is correct
15 Correct 492 ms 64468 KB Output is correct
16 Correct 456 ms 63264 KB Output is correct
17 Correct 474 ms 62468 KB Output is correct
18 Correct 511 ms 61856 KB Output is correct
19 Correct 470 ms 64536 KB Output is correct
20 Correct 457 ms 61740 KB Output is correct
21 Correct 488 ms 64416 KB Output is correct
22 Correct 473 ms 59116 KB Output is correct
23 Correct 454 ms 61988 KB Output is correct
24 Correct 515 ms 64020 KB Output is correct
25 Correct 248 ms 25220 KB Output is correct
26 Correct 266 ms 27420 KB Output is correct
27 Correct 497 ms 62140 KB Output is correct
28 Correct 466 ms 60472 KB Output is correct
29 Correct 446 ms 61756 KB Output is correct
30 Correct 482 ms 64780 KB Output is correct
31 Correct 484 ms 61776 KB Output is correct
32 Correct 458 ms 61972 KB Output is correct
33 Runtime error 296 ms 80428 KB Execution killed with signal 6
34 Halted 0 ms 0 KB -