#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 5;
int n, ans[N];
struct Item{
int cur, total, i;
bool operator < (const Item &sc) const{
return array<int, 3>{total, cur, i} < array<int, 3>{sc.total, sc.cur, sc.i};
}
};
Item arr[N];
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> arr[i].cur >> arr[i].total;
arr[i].i = i;
}
sort(arr + 1, arr + n + 1);
for(int i = 1; i <= n; i++){
for(int j = i + 1; j <= n; j++){
int tmp = min(arr[i].cur, arr[j].total - arr[j].cur);
arr[i].cur -= tmp, arr[j].cur += tmp;
}
}
for(int i = 1; i <= n; i++) ans[arr[i].i] = arr[i].cur;
cout << count(ans + 1, ans + n + 1, 0) << "\n";
for(int i = 1; i <= n; i++) cout << ans[i] << " ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
3 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
356 KB |
Output is correct |