답안 #72983

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
72983 2018-08-27T12:06:59 Z garyye Stove (JOI18_stove) C++14
100 / 100
39 ms 1532 KB
// author: gary
// created: 2018/08/27 12:55:13
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <limits>
#include <utility>
#include <functional>
#include <string>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <algorithm>
#include <iostream>
#include <sstream>
using namespace std;
#define SZ(x) ( (int) (x).size() )
#define ALL(c) (c).begin(), (c).end()
#define CNT(c, x) ((c).find(x) != (c).end())
typedef pair<int, int> pii;
typedef long long ll;
template<class T> bool cmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool cmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }

const int N = 1e5 + 10;

int t[N];
int a[N];
int n, k;

int main() {
  while(scanf("%d%d", &n, &k) != EOF) {
    for(int i = 0; i < n; i++) {
      scanf("%d", t + i);
      if(i > 0) {
        a[i - 1] = t[i] - t[i - 1] - 1;
      }
    }
    sort(a, a + n - 1);
    reverse(a, a + n - 1);
    int ans = t[n - 1] + 1 - t[0];

    for(int i = 0; i < k - 1; i++) {
      ans -= a[i];
    }

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

  return 0;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:44:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d", t + i);
       ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 3 ms 412 KB Output is correct
4 Correct 3 ms 476 KB Output is correct
5 Correct 3 ms 480 KB Output is correct
6 Correct 3 ms 560 KB Output is correct
7 Correct 2 ms 560 KB Output is correct
8 Correct 2 ms 616 KB Output is correct
9 Correct 3 ms 624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 3 ms 412 KB Output is correct
4 Correct 3 ms 476 KB Output is correct
5 Correct 3 ms 480 KB Output is correct
6 Correct 3 ms 560 KB Output is correct
7 Correct 2 ms 560 KB Output is correct
8 Correct 2 ms 616 KB Output is correct
9 Correct 3 ms 624 KB Output is correct
10 Correct 4 ms 628 KB Output is correct
11 Correct 4 ms 656 KB Output is correct
12 Correct 3 ms 688 KB Output is correct
13 Correct 4 ms 688 KB Output is correct
14 Correct 4 ms 744 KB Output is correct
15 Correct 4 ms 744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 3 ms 412 KB Output is correct
4 Correct 3 ms 476 KB Output is correct
5 Correct 3 ms 480 KB Output is correct
6 Correct 3 ms 560 KB Output is correct
7 Correct 2 ms 560 KB Output is correct
8 Correct 2 ms 616 KB Output is correct
9 Correct 3 ms 624 KB Output is correct
10 Correct 4 ms 628 KB Output is correct
11 Correct 4 ms 656 KB Output is correct
12 Correct 3 ms 688 KB Output is correct
13 Correct 4 ms 688 KB Output is correct
14 Correct 4 ms 744 KB Output is correct
15 Correct 4 ms 744 KB Output is correct
16 Correct 35 ms 1532 KB Output is correct
17 Correct 34 ms 1532 KB Output is correct
18 Correct 32 ms 1532 KB Output is correct
19 Correct 34 ms 1532 KB Output is correct
20 Correct 36 ms 1532 KB Output is correct
21 Correct 35 ms 1532 KB Output is correct
22 Correct 33 ms 1532 KB Output is correct
23 Correct 39 ms 1532 KB Output is correct
24 Correct 35 ms 1532 KB Output is correct