답안 #499293

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
499293 2021-12-27T20:33:26 Z inksamurai Pod starim krovovima (COCI20_psk) C++17
50 / 50
3 ms 332 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 308 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 292 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 308 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 3 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 320 KB Output is correct