//Test case unutma ve reset
//Sinirlari kontrol et
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1e9+7
#define OYY 1e12
#define ordu ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mid (start+end)/2
vector <pair<int,int>> v;
int dizi[1005];
int32_t main(){
ordu
int n;cin>>n;
int t[n],z[n];
int sum=0;
for(int i=0;i<n;i++){
cin>>t[i]>>z[i];
sum+=t[i];
v.push_back({z[i],i});
}
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
int k=0;
while(sum!=0){
if(sum>=v[k].first){
dizi[v[k].second]=v[k].first;
sum-=v[k].first;
}
else{
dizi[v[k].second]=sum;
sum=0;
}
k++;
}
cout<<n-k<<'\n';
for(int i=0;i<n;i++)cout<<dizi[i]<<" ";
cout<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |