Submission #872600

# Submission time Handle Problem Language Result Execution time Memory
872600 2023-11-13T12:36:22 Z vjudge1 Pod starim krovovima (COCI20_psk) C++17
50 / 50
1 ms 4596 KB
#include<bits/stdc++.h>
#ifdef LOCAL
#include "Essentials/algo/debug.h"
#else
#define debug(...) 69
#endif
using namespace std;

typedef long long     ll;
typedef pair<int,int> pii;

const int N = 5e5 + 23;
const ll inf = 1e18;

#define F           first
#define S           second
#define pb          push_back
#define kill(x)     cout<<x<<endl, exit(0);
#define all(x)      x.begin(),x.end()
#define sz(x)       (int)x.size()
#define lc          (v << 1)
#define rc          ((v<<1) |1)
#define int         ll

int n;
int a[N],b[N];
int sum= 0;
int ans[N];
vector<int> ord;

int32_t main() {
    cin.tie(nullptr)->sync_with_stdio(false);
	cin>>n;
	ord.resize(n);
	iota(all(ord), 0);
	for(int i = 0 ; i <n ; i++) {
		cin>>a[i] >> b[i];
		sum += a[i];
	}
	sort(all(ord) , [&] (int x,int y) { return b[x] > b[y];});
	for(int i = 0 ; i< n ; i++) {
		ans[ord[i]] = min(sum, b[ord[i]]);
		sum -= min(sum,b[ord[i]]);
	}
	int cnt =0;
	for(int i = 0 ; i< n ; i++) if(ans[i] == 0) cnt ++;
	cout<<cnt << '\n';
	for(int i = 0 ; i< n ; i++) cout<<ans[i] << ' ';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4596 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4568 KB Output is correct