Submission #83850

# Submission time Handle Problem Language Result Execution time Memory
83850 2018-11-11T11:33:44 Z nikolapesic2802 Karte (COCI18_karte) C++14
120 / 120
537 ms 28732 KB
/*
    - Keep a variable k- how many cards need to be wrong until the end.

*/
#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;
    karte.insert(INT_MAX);
    for(int i=0;i<n;i++)
    {
        int a;
        scanf("%i",&a);
        karte.insert(a);
    }
    vector<int> choose;
    for(int i=0;i<n;i++)
    {
        int a=*karte.lower_bound(k);
        if(a==INT_MAX)
        {
            a=*karte.begin();
        }
        choose.pb(a);
        karte.erase(karte.find(a));
        if(a!=k)
            k--;
        continue;
    }
    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:15: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:22: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 608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 608 KB Output is correct
2 Correct 2 ms 608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 672 KB Output is correct
2 Correct 2 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 672 KB Output is correct
2 Correct 3 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 672 KB Output is correct
2 Correct 3 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 672 KB Output is correct
2 Correct 3 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 732 KB Output is correct
2 Correct 3 ms 732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 6292 KB Output is correct
2 Correct 85 ms 6292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 204 ms 11864 KB Output is correct
2 Correct 197 ms 11864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 537 ms 28732 KB Output is correct
2 Correct 475 ms 28732 KB Output is correct