/*
ID: antwand1
TASK: barn1
LANG: C++
*/
#include <bits/stdc++.h>
#define ll long long
#define du long double
#define F first
#define S second
using namespace std;
const int N=1e3+1;
pair<ll,ll> a[N];
ll dp[N];
main()
{
//freopen("barn1.in","r",stdin);freopen("barn1.out","w",stdout);
ll n,sum=0,ans=0;
cin>>n;
for(int i=1;i<=n;i++){
int b;
cin>>b;
sum+=b;
cin>>a[i].F;
a[i].S=i;
}
sort(a+1,a+n+1);
reverse(a+1,a+n+1);
for(int i=1;i<=n;i++){
int g=min(sum,a[i].F);
sum-=g;
dp[a[i].S]=g;
}
for(int i=1;i<=n;i++)
if(dp[i]==0)ans++;
cout<<ans<<endl;
for(int i=1;i<=n;i++)cout<<dp[i]<<" ";cout<<endl;
}
Compilation message
psk.cpp:15:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
15 | main()
| ^
psk.cpp: In function 'int main()':
psk.cpp:37:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
37 | for(int i=1;i<=n;i++)cout<<dp[i]<<" ";cout<<endl;
| ^~~
psk.cpp:37:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
37 | for(int i=1;i<=n;i++)cout<<dp[i]<<" ";cout<<endl;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
396 KB |
Output is correct |