# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
844232 | vjudge1 | Pod starim krovovima (COCI20_psk) | C++17 | 1 ms | 596 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("unroll-loops,Ofast,O3")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define spc << " " <<
#define all(x) x.begin(), x.end()
#define ll long long
#define int long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define inf 1000000009
#define MOD 1000000007
using namespace std;
void solve(){
int n; cin >> n;
int tot=0;
ii arr[n+1];
for(int i=1; i<=n; i++){
int a,b; cin >> a >> b;
tot+=a;
arr[i]={b, i};
}
sort(arr+1, arr+n+1, greater<ii>());
int ans[n+1];
memset(ans, 0, sizeof(ans));
int ptr=1;
while(tot>0 && ptr<=n){
auto p=arr[ptr];
ans[p.nd]=min(p.st, tot);
tot-=p.st;
ptr++;
}
cout << n-ptr+1 << endl;
for(int i=1; i<=n; i++) cout << ans[i] << " ";
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
ll t=1;
//cin >> t;
while(t--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |