Submission #219808

# Submission time Handle Problem Language Result Execution time Memory
219808 2020-04-06T12:18:01 Z Nightlight Stove (JOI18_stove) C++14
100 / 100
39 ms 1784 KB
#include <bits/stdc++.h>
using namespace std;

int N, K;
int best[100005];

int main() {
  scanf("%d %d", &N, &K);
  if(N == 1) {
    puts("1");
    return 0;
  }
  int last, now, pertamax, terakhir;
  scanf("%d", &pertamax);
  last = pertamax;
  for(int i = 2; i < N; i++) {
    scanf("%d", &now);
    best[i - 1] = now - last - 1;
    last = now;
  }
  scanf("%d", &terakhir);
  best[N - 1] = terakhir - last - 1;
  sort(best + 1, best + N + 1, greater<int>());
  int ans = terakhir - pertamax + 1;
  for(int i = 1; i < K; i++) {
    ans -= best[i];
  }
  printf("%d", ans);
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:8:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &N, &K);
   ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &pertamax);
   ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &now);
     ~~~~~^~~~~~~~~~~~
stove.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &terakhir);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 29 ms 1664 KB Output is correct
17 Correct 39 ms 1784 KB Output is correct
18 Correct 29 ms 1664 KB Output is correct
19 Correct 29 ms 1664 KB Output is correct
20 Correct 28 ms 1664 KB Output is correct
21 Correct 29 ms 1664 KB Output is correct
22 Correct 29 ms 1664 KB Output is correct
23 Correct 29 ms 1536 KB Output is correct
24 Correct 29 ms 1664 KB Output is correct