답안 #710982

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
710982 2023-03-16T06:33:05 Z emptypringlescan Rainy Markets (CCO22_day1problem2) C++17
5 / 25
526 ms 63232 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=max(pop[i]-left-um[i],0LL);
		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];
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 195 ms 23764 KB Output is correct
5 Correct 227 ms 23764 KB Output is correct
6 Correct 223 ms 23776 KB Output is correct
7 Correct 234 ms 23784 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 360 ms 45472 KB Output is correct
11 Correct 371 ms 46988 KB Output is correct
12 Correct 466 ms 59236 KB Output is correct
13 Correct 478 ms 53464 KB Output is correct
14 Correct 280 ms 23764 KB Output is correct
15 Correct 468 ms 61044 KB Output is correct
16 Correct 526 ms 61060 KB Output is correct
17 Correct 476 ms 61024 KB Output is correct
18 Correct 467 ms 61148 KB Output is correct
19 Correct 511 ms 61164 KB Output is correct
20 Correct 481 ms 61132 KB Output is correct
21 Correct 439 ms 60920 KB Output is correct
22 Correct 455 ms 58464 KB Output is correct
23 Correct 490 ms 61036 KB Output is correct
24 Correct 447 ms 60220 KB Output is correct
25 Correct 239 ms 23780 KB Output is correct
26 Correct 229 ms 23784 KB Output is correct
27 Correct 465 ms 61052 KB Output is correct
28 Correct 493 ms 59116 KB Output is correct
29 Correct 452 ms 61388 KB Output is correct
30 Correct 477 ms 61836 KB Output is correct
31 Correct 472 ms 61372 KB Output is correct
32 Correct 497 ms 63232 KB Output is correct
33 Correct 248 ms 26040 KB Output is correct
34 Correct 277 ms 26168 KB Output is correct
35 Correct 280 ms 26636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Incorrect 1 ms 320 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Incorrect 1 ms 320 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 195 ms 23764 KB Output is correct
5 Correct 227 ms 23764 KB Output is correct
6 Correct 223 ms 23776 KB Output is correct
7 Correct 234 ms 23784 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 360 ms 45472 KB Output is correct
11 Correct 371 ms 46988 KB Output is correct
12 Correct 466 ms 59236 KB Output is correct
13 Correct 478 ms 53464 KB Output is correct
14 Correct 280 ms 23764 KB Output is correct
15 Correct 468 ms 61044 KB Output is correct
16 Correct 526 ms 61060 KB Output is correct
17 Correct 476 ms 61024 KB Output is correct
18 Correct 467 ms 61148 KB Output is correct
19 Correct 511 ms 61164 KB Output is correct
20 Correct 481 ms 61132 KB Output is correct
21 Correct 439 ms 60920 KB Output is correct
22 Correct 455 ms 58464 KB Output is correct
23 Correct 490 ms 61036 KB Output is correct
24 Correct 447 ms 60220 KB Output is correct
25 Correct 239 ms 23780 KB Output is correct
26 Correct 229 ms 23784 KB Output is correct
27 Correct 465 ms 61052 KB Output is correct
28 Correct 493 ms 59116 KB Output is correct
29 Correct 452 ms 61388 KB Output is correct
30 Correct 477 ms 61836 KB Output is correct
31 Correct 472 ms 61372 KB Output is correct
32 Correct 497 ms 63232 KB Output is correct
33 Correct 248 ms 26040 KB Output is correct
34 Correct 277 ms 26168 KB Output is correct
35 Correct 280 ms 26636 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 320 KB Output is correct
38 Incorrect 1 ms 320 KB Output isn't correct
39 Halted 0 ms 0 KB -