Submission #732231

# Submission time Handle Problem Language Result Execution time Memory
732231 2023-04-28T18:41:33 Z vjudge1 Pod starim krovovima (COCI20_psk) C++17
50 / 50
1 ms 368 KB
#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int32_t main(){
	fast;
	int n;
	cin>>n;
	int a[n],b[n],s=0;
	vector<pair<int,int>>v;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		s+=a[i];
		v.pb({b[i],i});
	}
	sort(all(v));
	int ans[n],cnt=0;
	for(int i=v.size()-1;i>=0;i--){
		if(s==0)cnt++;
		ans[v[i].ss]=min(s,v[i].ff);
		s-=min(s,v[i].ff);
	}
	cout<<cnt<<endl;
	for(int i=0;i<n;i++)cout<<ans[i]<<" ";
	cout<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 368 KB Output is correct