Submission #41091

# Submission time Handle Problem Language Result Execution time Memory
41091 2018-02-12T15:24:44 Z IvanC Stove (JOI18_stove) C++14
100 / 100
35 ms 3056 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
const int MAXN = 1e5 + 10;
ll vetor[MAXN],N,K;
ii dp[MAXN];
ii solve(ll W){
	dp[0] = ii(0,0);
	ii best = ii(-vetor[1] + 1,0);
	for(ll i = 1;i<=N;i++){
		dp[i] = ii(best.first + vetor[i] + W,best.second - 1);
		best = min(best, ii(-vetor[i+1] + 1 + dp[i].first,dp[i].second) );
	}
	return dp[N];
}

int main(){
	cin.tie(0);ios_base::sync_with_stdio(0);
	cin >> N >> K;
	for(ll i = 1;i<=N;i++) cin >> vetor[i];
	ll ini = 0, fim = (ll)2*1e9, resp = -1,meio;
	while(ini <= fim){
		meio = (ini+fim)/2;
		if(abs(solve(meio).second) >= K){
			resp = meio;
			ini = meio + 1;
		}
		else{
			fim = meio - 1;
		}
	}
	cout << solve(resp).first - K*resp << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 368 KB Output is correct
3 Correct 2 ms 552 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 368 KB Output is correct
3 Correct 2 ms 552 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 704 KB Output is correct
11 Correct 2 ms 704 KB Output is correct
12 Correct 3 ms 704 KB Output is correct
13 Correct 3 ms 704 KB Output is correct
14 Correct 2 ms 704 KB Output is correct
15 Correct 2 ms 704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 368 KB Output is correct
3 Correct 2 ms 552 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 704 KB Output is correct
11 Correct 2 ms 704 KB Output is correct
12 Correct 3 ms 704 KB Output is correct
13 Correct 3 ms 704 KB Output is correct
14 Correct 2 ms 704 KB Output is correct
15 Correct 2 ms 704 KB Output is correct
16 Correct 28 ms 2924 KB Output is correct
17 Correct 27 ms 2924 KB Output is correct
18 Correct 27 ms 2924 KB Output is correct
19 Correct 27 ms 2924 KB Output is correct
20 Correct 35 ms 2924 KB Output is correct
21 Correct 30 ms 2924 KB Output is correct
22 Correct 28 ms 2928 KB Output is correct
23 Correct 29 ms 2928 KB Output is correct
24 Correct 28 ms 3056 KB Output is correct