Submission #48442

# Submission time Handle Problem Language Result Execution time Memory
48442 2018-05-13T14:53:24 Z arman_ferdous Stove (JOI18_stove) C++17
100 / 100
32 ms 11172 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5+10;
long long arr[N], dif[N];

int main() {
	int n, k;
	scanf("%d %d", &n, &k);
	for(int i = 0; i < n; i++)
		scanf("%lld", &arr[i]);

	for(int i = 0; i+1 < n; i++)
		dif[i] = arr[i+1] - arr[i] - 1;
	sort(dif,dif+n-1,greater<int>());

	long long ans = arr[n-1] - arr[0] + 1;
	for(int i = 1; i < k; i++) 
		ans -= dif[i-1];
	
	printf("%lld", ans);
	return 0;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:9:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &k);
  ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:11:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &arr[i]);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 472 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 528 KB Output is correct
6 Correct 2 ms 532 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 3 ms 648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 472 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 528 KB Output is correct
6 Correct 2 ms 532 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 3 ms 648 KB Output is correct
10 Correct 3 ms 652 KB Output is correct
11 Correct 3 ms 864 KB Output is correct
12 Correct 3 ms 864 KB Output is correct
13 Correct 3 ms 864 KB Output is correct
14 Correct 3 ms 864 KB Output is correct
15 Correct 3 ms 864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 472 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 528 KB Output is correct
6 Correct 2 ms 532 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 3 ms 648 KB Output is correct
10 Correct 3 ms 652 KB Output is correct
11 Correct 3 ms 864 KB Output is correct
12 Correct 3 ms 864 KB Output is correct
13 Correct 3 ms 864 KB Output is correct
14 Correct 3 ms 864 KB Output is correct
15 Correct 3 ms 864 KB Output is correct
16 Correct 28 ms 3328 KB Output is correct
17 Correct 29 ms 4404 KB Output is correct
18 Correct 32 ms 5312 KB Output is correct
19 Correct 28 ms 6340 KB Output is correct
20 Correct 26 ms 7300 KB Output is correct
21 Correct 27 ms 8260 KB Output is correct
22 Correct 27 ms 9244 KB Output is correct
23 Correct 26 ms 10208 KB Output is correct
24 Correct 26 ms 11172 KB Output is correct