답안 #844323

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
844323 2023-09-05T12:19:44 Z vjudge1 Pod starim krovovima (COCI20_psk) C++14
40 / 50
1 ms 348 KB
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1, T2> p){ return os << p.first << " " << p.second; }

void solve(void){
	int x;
	cin >> x;
	vector<pair<int, int>> a(x);
	vector<int> dolu(x), son(x,0);
	int sum = 0;
	for(int i=0; i<x; i++){
		cin >> dolu[i];
		sum += dolu[i];
		cin >> a[i].first;
		a[i].second = i;
	}

	sort(a.begin(), a.end(), [](pair<int,int> a, pair<int,int> b){ return a.first > b.first; } );

	int ans = 0;
	for(int i=0; i<x; i++){
		if(a[i].first <= sum){
			sum -= a[i].first;
			son[a[i].second] = a[i].first;
		}else{
			son[a[i].second] = sum;
			sum -= sum;

			ans += !son[a[i].second];
		}
	}
	cout << ans  << "\n";

	for(auto gh: son)
		cout << gh << " ";
	cout << "\n";


}

int main(){
	int t=1;
//	cin >> t;
	while(t--)
		solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Incorrect 1 ms 344 KB Output isn't correct
10 Incorrect 1 ms 344 KB Output isn't correct