Submission #844295

# Submission time Handle Problem Language Result Execution time Memory
844295 2023-09-05T12:07:24 Z vjudge1 Pod starim krovovima (COCI20_psk) C++17
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; } );

#ifdef DEBUG
	for(int i=0; i<x; i++){
		cout << a[i] << "\n";
	}
#endif

	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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Incorrect 1 ms 344 KB Output isn't correct
10 Incorrect 1 ms 348 KB Output isn't correct