Submission #238591

# Submission time Handle Problem Language Result Execution time Memory
238591 2020-06-12T03:34:44 Z rahul_a_n Stove (JOI18_stove) C++14
100 / 100
74 ms 3292 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)
#define PI pair<int,int>
#define PL pair<long int,long int>
#define PLL pair<ll,ll>
#define Tcase int t;cin>>t;while(t--)
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define MAXN 200005
#define F first
#define S second
int main() {

/*#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif*/
	ll n, k;
	cin >> n >> k;
	long int t[n];
	vector<long int>ans;
	for (int i = 0; i < n; i++)cin >> t[i];
	for (int i = 0; i < n - 1; i++)ans.pb(t[i] - t[i + 1] + 1);
	ll tot = t[n - 1] - t[0] + 1;
  ll tot1 = t[n - 1] - t[0] + 1;
	sort(all(ans));
  for(int i = 0;i < k - 1; i++)tot1+=ans[i];
  reverse(all(ans));
	for (int i = 0; i < k - 1; i++)tot += ans[i];
	cout << min(tot,tot1) << "\n";
  ans.clear();
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 4 ms 256 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 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 7 ms 512 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 7 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 7 ms 512 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 7 ms 512 KB Output is correct
16 Correct 74 ms 3184 KB Output is correct
17 Correct 73 ms 3184 KB Output is correct
18 Correct 73 ms 3184 KB Output is correct
19 Correct 73 ms 3292 KB Output is correct
20 Correct 72 ms 3236 KB Output is correct
21 Correct 72 ms 3184 KB Output is correct
22 Correct 73 ms 3184 KB Output is correct
23 Correct 73 ms 3188 KB Output is correct
24 Correct 74 ms 3184 KB Output is correct