Submission #499293

#TimeUsernameProblemLanguageResultExecution timeMemory
499293inksamuraiPod starim krovovima (COCI20_psk)C++17
50 / 50
3 ms332 KiB
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() #define rep(i,n) for(int i=0;i<n;i++) #define crep(i,x,n) for(int i=x;i<n;i++) #define drep(i,n) for(int i=n-1;i>=0;i--) #define vec(...) vector<__VA_ARGS__> #define _3qplfh5 ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0) using namespace std; typedef long long ll; typedef long double ld; using tpii=pair<int,pair<int,int>>; using pii=pair<int,int>; using vi=vector<int>; using vll=vector<long long>; int main(){ _3qplfh5; int n; cin>>n; vec(tpii) a(n); rep(i,n){ cin>>a[i].fi>>a[i].se.fi; a[i].se.se=i; } sort(all(a),[](tpii l,tpii r){ return l.se.fi<r.se.fi; }); while(true){ bool pok=0; rep(i,n){ if(i+1<n and a[i].fi and a[i+1].se.fi>a[i+1].fi){ pok=1; int diff=min(a[i].fi,a[i+1].se.fi-a[i+1].fi); a[i].fi-=diff; a[i+1].fi+=diff; } } if(not pok) break; } int ans=0; rep(i,n){ ans+=(a[i].fi==0); } cout<<ans<<"\n"; vi pans(n,0); rep(i,n){ pans[a[i].se.se]=a[i].fi; } rep(i,n){ cout<<pans[i]<<" "; } cout<<"\n"; // return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...