// Aber der schlimmste Fiend, dem du begegnen kannst, wirst du immer dir selber sein
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
#define int long long int
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ff first
#define ss second
#define pb push_back
#define rev reverse
#define all(x) x.begin(),x.end()
#define acc accumulate
#define sz size()
#define MOD 1000000007
#define rall(x) x.rbegin(),x.rend()
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const int N = 5e5 + 5;
inline void solve(){
int n;
cin >> n;
int a[n];
pair<int, int> b[n];
rep(i, 0, n) cin >> a[i] >> b[i].ff;
rep(i, 0, n) b[i].ss = i;
sort(b, b+n);
int sum = acc(a, a+n, 0LL);
rev(b, b+n);
int ans[n];
int in = 0;
while(sum > 0){
ans[b[in].ss] = min(b[in].ff, sum);
sum = max(0LL, sum - b[in].ff);
in++;
}
while(in < n) ans[b[in].ss] = 0, in++;
int cnt = 0;
rep(i, 0, n) if(ans[i] == 0) cnt++;
cout << cnt << endl;
rep(i, 0, n) cout << ans[i] << " ";
cout << endl;
}
int32_t main(){
fast_io
int t;
t = 1;
while(t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |