Submission #197349

# Submission time Handle Problem Language Result Execution time Memory
197349 2020-01-20T13:30:02 Z abil Stove (JOI18_stove) C++14
100 / 100
28 ms 2356 KB
# include <bits/stdc++.h>

# define fr first
# define sc second
# define pb push_back
# define sz(s) s.size()
# define all(s) s.begin(),s.end()
//# define int long long

using namespace std;

const long long N = (1e6 + 10);
const long long mod = (1e9 + 7);
const long long inf = (1e9 + 7);

int a[N];

main()
{
  int n, k;
  cin >> n >> k;
  vector<int > vec;
  for(int i = 1;i <= n; i++){
		scanf("%d", &a[i]);
  }
  for(int i = 2;i <= n; i++){
		vec.pb(max((a[i]) - (a[i - 1] + 1),0));
  }
  sort(all(vec));
  k--;
  int ans = a[n] + 1 - a[1];
	for(int i = vec.size() - 1;i >= 0; i--){
		if(!k){
			break;
		}
		k--;
		ans -= vec[i];
	}
	cout << ans;
}

Compilation message

stove.cpp:18:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
stove.cpp: In function 'int main()':
stove.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 380 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 380 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 27 ms 2356 KB Output is correct
17 Correct 28 ms 2328 KB Output is correct
18 Correct 27 ms 2292 KB Output is correct
19 Correct 27 ms 2292 KB Output is correct
20 Correct 27 ms 2292 KB Output is correct
21 Correct 27 ms 2292 KB Output is correct
22 Correct 27 ms 2296 KB Output is correct
23 Correct 27 ms 2292 KB Output is correct
24 Correct 27 ms 2292 KB Output is correct