Submission #844273

# Submission time Handle Problem Language Result Execution time Memory
844273 2023-09-05T11:57:37 Z vjudge1 Pod starim krovovima (COCI20_psk) C++17
50 / 50
1 ms 348 KB
#include <bits/stdc++.h>
#define fast cin.tie(0)->sync_with_stdio(0);
#define int long long
#define inf ((int)1e18)
#define N 1005
using namespace std;
vector <pair<int, int> > glass(N);
vector <int> ans(N);

int32_t main(){
	fast
	int n;
	cin>>n;
	int all = 0;
	for(int i = 0; i < n; i++) {
		int amount;
		glass[i].second = i;
		cin>>amount>>glass[i].first;
		all += amount;
	}
	sort(glass.begin(), glass.end());
	reverse(glass.begin(), glass.end());
	int fans;
	for(int i = 0; i < n; i++) {
		if(all <= 0) {fans = 0; break; };
		ans[glass[i].second] = min(glass[i].first, all);
		all -= glass[i].first;
		if(all <= 0) {
			fans = n - i - 1;
			break;
		}
	}
	cout<<fans<<"\n";
	for(int i = 0; i < n; i++) {
		cout<<ans[i]<<" ";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct