답안 #107429

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
107429 2019-04-24T08:13:43 Z evpipis Stove (JOI18_stove) C++14
100 / 100
40 ms 2420 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back

const int len = 1e5+5;
int arr[len];
vector<int> vec;

bool comp(int a, int b){
    return (a > b);
}

int main(){
    int n, k, ans;
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; i++)
        scanf("%d", &arr[i]);
    k = min(k-1, n-1);

    for (int i = 1; i < n; i++)
        vec.pb(arr[i+1]-arr[i]-1);
    sort(vec.begin(), vec.end(), comp);

    ans = arr[n]-arr[1]+1;
    for (int i = 0; i < k; i++)
        ans -= vec[i];

    printf("%d\n", ans);
    return 0;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &arr[i]);
         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 40 ms 2292 KB Output is correct
17 Correct 28 ms 2292 KB Output is correct
18 Correct 33 ms 2300 KB Output is correct
19 Correct 38 ms 2300 KB Output is correct
20 Correct 28 ms 2300 KB Output is correct
21 Correct 31 ms 2292 KB Output is correct
22 Correct 31 ms 2292 KB Output is correct
23 Correct 29 ms 2300 KB Output is correct
24 Correct 33 ms 2420 KB Output is correct