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 time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
6 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
6 ms |
384 KB |
Output is correct |