Submission #890169

# Submission time Handle Problem Language Result Execution time Memory
890169 2023-12-20T16:13:53 Z HADI_T Pod starim krovovima (COCI20_psk) C++14
50 / 50
2 ms 604 KB
#include<bits/stdc++.h>
#define int long long
#define pb(x) push_back(x)
#define in(x) insert(x)
#define F first
#define S second
#define endl '\n'
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
const int M=1e9+7;
const int N=2e5+10;
using namespace std;
int32_t main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
cin>>n;
int sum = 0;
int ans[n+10]={0};
pair<int,int>a[n+10];
for(int i=1;i<=n;i++)
{
    int x,y;
    cin>>x>>y;
    sum += x;
    a[i]={y,i};
}
sort(a+1,a+1+n);
for(int i = n;i>=1;i--)
{
    int ad = min(sum , a[i].F);
    ans[a[i].S] += ad;
    sum -= ad;
}
int cnt = 0;
for(int i=1;i<=n;i++)
{
    if(ans[i] == 0)
        cnt++;
}
cout<<cnt<<endl;
for(int i=1;i<=n;i++)
    cout<<ans[i]<<' ';
cout<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 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 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 348 KB Output is correct