제출 #231813

#제출 시각아이디문제언어결과실행 시간메모리
231813CodeTiger927Pod starim krovovima (COCI20_psk)C++14
50 / 50
6 ms384 KiB
using namespace std;

#include <iostream>
#include <queue>

int N;
priority_queue<pair<long long,int>> pq;
int ans;
long long total = 0;
long long arr[1005];

int main() {
	cin >> N;
	ans = N;
	for(int i = 0;i < N;i++) {
		long long a,b;
		cin >> a >> b;
		pq.push({b,i});
		total += a;
	}
	while(total > 0) {
		ans--;
		pair<long long,int> cur = pq.top();
		pq.pop();
		if(total > cur.first) {
			arr[cur.second] = cur.first;
		}else{
			arr[cur.second] = total;
		}
		total -= cur.first;
	}
	cout << ans << endl;
	for(int i = 0;i < N;i++) {
		cout << arr[i] << " ";
	}
	cout << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...