Submission #1092746

# Submission time Handle Problem Language Result Execution time Memory
1092746 2024-09-24T23:01:24 Z Hacv16 Pod starim krovovima (COCI20_psk) C++17
50 / 50
1 ms 360 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long int

const int MAX = 2e5 + 10;

int n, t[MAX], z[MAX];
int ans[MAX];

int32_t main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;

	for(int i = 1; i <= n; i++)
		cin >> t[i] >> z[i];

	vector<int> glasses(n);
	iota(glasses.begin(), glasses.end(), 1);

	sort(glasses.begin(), glasses.end(), [&](int i, int j){
		return z[i] > z[j];
	});

	int totalDrink = accumulate(t + 1, t + 1 + n, 0LL);
	int respZero = 0;

	for(auto glassId : glasses)
	{
		ans[glassId] = min(z[glassId], totalDrink);
		totalDrink -= min(z[glassId], totalDrink);

		if(!ans[glassId]) respZero++;
	}

	cout << respZero << '\n';

	for(int i = 1; i <= n; i++)
		cout << ans[i] << ' ';

	cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 360 KB Output is correct
2 Correct 0 ms 360 KB Output is correct
3 Correct 0 ms 360 KB Output is correct
4 Correct 0 ms 360 KB Output is correct
5 Correct 0 ms 360 KB Output is correct
6 Correct 0 ms 360 KB Output is correct
7 Correct 0 ms 360 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 0 ms 360 KB Output is correct