#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define pii pair<int,int>
#define bg begin
#define vi vector<int>
#define vvi vector<vi>
#define vp vector<pii>
#define ppi pair<pii,int>
#define endl '\n'
#define triple tuple<int,int,int>
#define ppp pair<pii,pii>
#define pip pair<int,pii>
#define vpp vector<ppi>
#define sp << " " <<
#define ff first
#define ss second
#define F(xxx,n) for (int xxx=1;xxx<=n;++xxx)
#define FF(xxx,sss,yyy) for (int xxx=sss;xxx<=yyy;++xxx)
#define pb push_back
const int MOD = 1e9+7;
void solve() {
int n;
cin >> n;
vi a(n+1),cap(n+1),full(n+1,0);
F(i,n) cin >> a[i] >> cap[i];
vp ps(n+1);
F(i,n) ps[i] = {cap[i],i};
sort(cap.bg()+1,cap.end(),greater<int>());
sort(ps.bg()+1,ps.end(),greater<pii>());
int total = accumulate(a.bg()+1,a.end(),0ll);
int ptr = 1;
while (total) {
if (total <= cap[ptr]) {
cap[ptr]-=total;
full[ps[ptr].ss]+=total;
total = 0;
}else {
total-=cap[ptr];
full[ps[ptr].ss] = cap[ptr];
cap[ptr] = 0;
ptr++;
}
}
int bos = 0;
F(i,n) if (!full[i]) bos++;
cout << bos << endl;
F(i,n) {
cout << full[i] << " ";
}
cout << endl;
}
signed main() {
#ifdef Local
freopen("input.in","r",stdin);
freopen("input.out","w",stdout);
#endif
ios_base::sync_with_stdio(0);cin.tie(0);
int t = 1;
//cin >> t;
while (t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |