답안 #730646

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730646 2023-04-26T08:32:16 Z stefdasca Karte (COCI18_karte) C++14
120 / 120
114 ms 13828 KB
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    int n, m;
    cin >> n >> m;
 
    vector<int> nums(n);
    for (int i = 0; i < n; i++) 
        cin >> nums[i];
    
    sort(nums.begin(), nums.end());
    int correct = n - m;
 
    vector<int> a;
 
    for (int i = correct - 1; i >= 0; i--) 
        a.push_back(nums[i]);
    
 
    vector<int> b;
 
    for (int i = n - 1; i >= correct; i--) 
        b.push_back(nums[i]);
 
    vector<int> vals;
 
    for (auto x: a) 
      	vals.push_back(x);
    for (auto x: b) 
      	vals.push_back(x);
 
    int bad = 0;
 
    for (int i = n - 1; i >= 0; i--) 
        if (vals[i] > bad) 
            bad++;
 
    if (bad == m) 
    {
        for (int i = 0; i < n; i++) 
            cout << vals[i] << " ";
        cout << '\n';
    }
    else
        cout << -1 << '\n';
	return 0; 
}

Compilation message

karte.cpp: In function 'int main()':
karte.cpp:49:5: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
   49 |     else
      |     ^~~~
karte.cpp:51:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
   51 |  return 0;
      |  ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 3100 KB Output is correct
2 Correct 16 ms 2472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 5820 KB Output is correct
2 Correct 36 ms 4608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 13828 KB Output is correct
2 Correct 82 ms 11144 KB Output is correct