#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define int long long
struct Glass {
int index, vol, cap;
};
int n, t, z, liquid = 0;
vector<Glass> glasses;
signed main() {
cin >> n;
glasses.resize(n);
for (int i = 0; i < n; i++) {
cin >> t >> z;
liquid += t;
glasses[i].index = i, glasses[i].vol = t, glasses[i].cap = z;
}
if (liquid > 0) {
sort(glasses.begin(), glasses.end(),
[](Glass g1, Glass g2) { return g1.cap > g2.cap; });
bool said = 0;
for (int i = 0; i < n; i++) {
int pour = min(glasses[i].cap, liquid);
glasses[i].vol = pour;
liquid -= pour;
if (liquid <= 0 and not said) {
cout << n - i - 1 << endl;
said = 1;
}
}
sort(glasses.begin(), glasses.end(),
[](Glass g1, Glass g2) { return g1.index < g2.index; });
} else {
cout << n << endl;
}
for (Glass g : glasses) {
cout << g.vol << ' ';
}
cout << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |