답안 #667197

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
667197 2022-11-30T17:19:03 Z nasir_bashirov Stove (JOI18_stove) C++11
100 / 100
54 ms 2380 KB
#include <bits/stdc++.h>
using namespace std;


int main(){
    int n , k;
    cin >> n >> k;
    int a[n+1];
    a[0] = 0;
    vector<int>dif(n);
    for(int i=1;i<=n;i++){
        cin >> a[i];
        if(i > 1){
            dif.push_back(a[i]-a[i-1]-1);
        }
    }
    if(n == k){
        cout << n;
        return 0;
    }
    sort(dif.begin(),dif.end());
    int res = n;
    k--;
    for(int i=0;i<dif.size()-k;i++){
        res += dif[i];
    }
    cout << res;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i=0;i<dif.size()-k;i++){
      |                 ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 368 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 368 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 312 KB Output is correct
16 Correct 44 ms 2352 KB Output is correct
17 Correct 46 ms 2356 KB Output is correct
18 Correct 47 ms 2380 KB Output is correct
19 Correct 45 ms 2360 KB Output is correct
20 Correct 44 ms 2372 KB Output is correct
21 Correct 44 ms 2332 KB Output is correct
22 Correct 44 ms 2368 KB Output is correct
23 Correct 45 ms 2356 KB Output is correct
24 Correct 54 ms 2352 KB Output is correct