제출 #844224

#제출 시각아이디문제언어결과실행 시간메모리
844224vjudge1Pod starim krovovima (COCI20_psk)C++17
50 / 50
1 ms352 KiB
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #include "/Users/kutay/CP/templates/debug.h" #else #define debug(...) void(38) #endif #define int long long int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<pair<int, pair<int, int>>> a(n); int l = 0, s = 0; for (int i = 0; i < n; i++) { cin >> a[i].second.first >> a[i].second.second; l += a[i].second.first; s += a[i].second.second; a[i].first = i; } sort(a.begin(), a.end(), [](pair<int, pair<int, int>> x, pair<int, pair<int, int>> y) { return x.second.second < y.second.second; }); int k = s - l, cnt = 0; for (int i = 0; i < n; i++) { if (a[i].second.second <= k) { a[i].second.first = 0; k -= a[i].second.second; cnt++; } else { a[i].second.first = a[i].second.second - k; k = 0; } } sort(a.begin(), a.end()); cout << cnt << '\n'; for (int i = 0; i < n; i++) cout << a[i].second.first << " "; cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...