Submission #580094

# Submission time Handle Problem Language Result Execution time Memory
580094 2022-06-20T15:04:14 Z vqpahmad Karte (COCI18_karte) C++14
120 / 120
114 ms 7780 KB
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define all(a) a.begin(),a.end()
#define mod (ll)(10000007)
using namespace std;
const int mx = 1e6 + 15;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(all(a),greater<int>());
    sort(a.begin(),a.begin()+k);
    bool flag = 1;
    int cnt = 0;
    for (int i=0;i<n;i++){
        if (a[i] > cnt){
            cnt++;
        }
    }
    if (cnt==k){
        for (int i=n-1;i>=0;i--){
            cout << a[i] << ' ' ;
        }
    }
    else cout << -1 ;
}

Compilation message

karte.cpp: In function 'int main()':
karte.cpp:22:10: warning: unused variable 'flag' [-Wunused-variable]
   22 |     bool flag = 1;
      |          ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 1732 KB Output is correct
2 Correct 16 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 3272 KB Output is correct
2 Correct 31 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 7780 KB Output is correct
2 Correct 71 ms 5208 KB Output is correct