Submission #83840

# Submission time Handle Problem Language Result Execution time Memory
83840 2018-11-11T11:12:20 Z nikolapesic2802 Karte (COCI18_karte) C++14
84 / 120
925 ms 52192 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back

int main()
{
    int n,k;
    scanf("%i %i",&n,&k);
    int t=k;
    multiset<int> karte;
    multiset<int,greater<int> > revkarte;
    revkarte.insert(-1);
    karte.insert(INT_MAX);
    for(int i=0;i<n;i++)
    {
        int a;
        scanf("%i",&a);
        karte.insert(a);
        revkarte.insert(a);
    }
    vector<int> choose;
    for(int i=0;i<n;i++)
    {
        //if(i!=0)
            //printf("Uzeo %i\n",choose[i-1]);
        if(k>n-i-1){
            set<int>::iterator it=karte.begin();
            if(*it==k-1)
            {
                it=karte.upper_bound(k-1);
            }
            int b=*it;
            choose.pb(b);
            karte.erase(karte.find(b));
            revkarte.erase(revkarte.find(b));
            k--;
            continue;
        }
        int a=*karte.lower_bound(k);
        if(a==k)
        {
            choose.pb(a);
            karte.erase(karte.find(k));
            revkarte.erase(revkarte.find(k));
            continue;
        }
        if(a==INT_MAX)
        {
            int b=*revkarte.upper_bound(k-1);
            if(b==-1)
            {
                karte.erase(karte.find(k-1));
                revkarte.erase(revkarte.find(k-1));
                choose.pb(k-1);
                k--;
                continue;
            }
            choose.pb(b);
            karte.erase(karte.find(b));
            revkarte.erase(revkarte.find(b));
            k--;
            continue;
        }
        multiset<int>::iterator it;
        it=karte.end();
        it--;
        it--;
        a=*it;
        choose.pb(a);
        karte.erase(karte.find(a));
        revkarte.erase(revkarte.find(a));
        k--;
    }
    int tr=0;
    int cnt=0;
    for(int i=n-1;i>=0;i--)
    {
        //printf("%i ",choose[i]);
        if(choose[i]==tr)
        {
            continue;
        }
        cnt++;
        tr++;
    }
    if(cnt==t)
    {
        for(int i=0;i<n;i++)
        {
            printf("%i ",choose[i]);
        }
    }
    else
    {
        printf("-1");
    }
    return 0;
}

Compilation message

karte.cpp: In function 'int main()':
karte.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i %i",&n,&k);
     ~~~~~^~~~~~~~~~~~~~~
karte.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&a);
         ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Incorrect 2 ms 512 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 728 KB Output is correct
2 Incorrect 3 ms 728 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 728 KB Output is correct
2 Correct 3 ms 728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 728 KB Output is correct
2 Incorrect 4 ms 752 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 768 KB Output is correct
2 Correct 5 ms 784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 11068 KB Output is correct
2 Correct 131 ms 11068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 359 ms 21312 KB Output is correct
2 Correct 321 ms 21312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 904 ms 52192 KB Output is correct
2 Correct 925 ms 52192 KB Output is correct