답안 #197990

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197990 2020-01-24T12:41:45 Z ami Pod starim krovovima (COCI20_psk) C++17
50 / 50
3 ms 376 KB
#include <bits/stdc++.h>
#define sz(c)       int(c.size())
#define rep(i,a,b)  for (int i=a; i<(b); ++i)
#define per(i,a,b)  for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto __VA_ARGS__:(c))
using namespace std;
using ll = long long;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int n;
	cin>>n;
	vector<pair<int,int>> g(n);
	fore(g,&i) cin>>i.first>>i.second;

	vector<int> ord(n);
	iota(ord.begin(),ord.end(),0);

	sort(ord.begin(),ord.end(),[&](int a,int b) {
		return g[a].second>g[b].second;
	});

	ll tot=0;
	fore(g,&i) tot+=i.first;

	int res=0;
	fore(ord,i) {
		g[i].first=(int)min(tot,(ll)g[i].second);
		tot-=g[i].first;
		if (g[i].first==0) res++;
	}

	cout<<res<<'\n';
	rep(i,0,sz(g)) cout<<g[i].first<<" \n"[i+1==sz(g)];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct