Submission #447046

# Submission time Handle Problem Language Result Execution time Memory
447046 2021-07-24T10:00:21 Z grt Pod starim krovovima (COCI20_psk) C++17
50 / 50
1 ms 332 KB
#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

using namespace std;

using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;

const int nax = 1000 + 10;
int n;
vector<pi>a;
ll sum;
int cap[nax];


int main() {_
	cin >> n;
	a.resize(n);
	for(int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		sum += x;
		cin >> a[i].ST;
		a[i].ND = i;
	}
	sort(a.rbegin(), a.rend());
	int cnt = 0;
	for(auto x : a) {
		cap[x.ND] = min(sum, (ll)x.ST);
		sum -= min(sum, (ll)x.ST);
		if(cap[x.ND] == 0) {
			cnt++;
		}
	}
	cout << cnt << "\n";
	for(int i = 0; i < n; ++i) cout << cap[i] << " ";
	
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct