#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define int long long
using namespace std;
typedef tuple<int, int, int> iii;
typedef long long ll;
const int mod =998244353;
int n, sum;
int t[1005], ans[1005];
pair<int, int> v[1005];
int32_t main(){
fast;
cin>>n;
for(int i=1;i<=n;i++){
cin>>t[i]>>v[i].fi;
v[i].se=i;
sum+=t[i];
}
sort(v+1, v+n+1, greater<pair<int, int>>());
for(int i=1;i<=n;i++){
if(sum<=0){
cout<<n-i+1<<endl;
break;
}
ans[v[i].se]=min(v[i].fi, sum);
sum-=v[i].fi;
}
for(int i=1;i<=n;i++){
cout<<ans[i]<<" ";
}
cout<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
460 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 |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |