답안 #580988

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
580988 2022-06-22T07:40:38 Z AGE Pod starim krovovima (COCI20_psk) C++14
50 / 50
2 ms 340 KB
#include<bits/stdc++.h>
#define F first
#define S second
#define int long long
#define pb push_back

using namespace std;
const int N=1e6,M=2e3,mod=1e9+7;
pair<int,pair<int,int> > a[N];
int anss[N];
main()
{

    int n;
    cin>>n;

    for(int i=0;i<n;i++){
        cin>>a[i].S.F>>a[i].F;
        a[i].S.S=i;
    }

    sort(a,a+n);
    int ans=0;

    for(int i=1;i<=n;i++){

        int emptyy=0;
        for(int j=0;j<i;j++){
            emptyy+=a[j].S.F;
        }
        int x=0;
        for(int j=i;j<n;j++)
            x+=a[j].F-a[j].S.F;

        if(x>=emptyy)
            ans=i;

    }

    int xx=0;
    for(int i=0;i<ans;i++)
        xx+=a[i].S.F;

    for(int i=0;i<ans;i++){
        anss[a[i].S.S]=0;
    }

    for(int i=ans;i<n;i++){

        int xxx=min(a[i].F-a[i].S.F,xx);
        xx-=xxx;
        anss[a[i].S.S]=a[i].S.F+xxx;

    }

    int cnt=0;
    for(int i=0;i<n;i++)
        if(anss[i]==0)
            cnt++;

    cout<<cnt<<endl;
    for(int i=0;i<n;i++)
        cout<<anss[i]<<" ";
    cout<<endl;
    return 0;
}

Compilation message

psk.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main()
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 340 KB Output is correct