Submission #388374

# Submission time Handle Problem Language Result Execution time Memory
388374 2021-04-11T07:04:38 Z warner1129 Stove (JOI18_stove) C++17
0 / 100
1 ms 460 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e5 + 5;

int arr[maxn];
int n, m;

pair<int, int> DP(int p) {
	static int dp[maxn] = {};
	static int cnt[maxn] = {};
	int pre = 0;
	for (int i = 1; i <= n; i++) {
		dp[i] = dp[pre] + (arr[i] - arr[pre+1] + 1) + p;
		cnt[i] = cnt[pre] + 1;
		if (dp[i] - arr[i+1] < dp[pre] - arr[pre+1]) pre = i;
	}
	return {dp[n] - cnt[n] * p, cnt[n]};
}

void solve() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> arr[i];
	m = min(m, n);
	int l = 0, r = arr[n];
	while (l <= r) {
		int v, c;
		int mid = (l+r)>>1;
		tie(v, c) = DP(mid);
		if (c <= m) r = mid-1;
		else l = mid+1;
	}
	long long lv, lc, rv, rc;
	tie(lv, lc) = DP(l);
	tie(rv, rc) = DP(r);
	cout << lv + (rv - lv) * (m - lc) / (rc - lc) << '\n';	
}

signed main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Runtime error 1 ms 460 KB Execution killed with signal 8
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Runtime error 1 ms 460 KB Execution killed with signal 8
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Runtime error 1 ms 460 KB Execution killed with signal 8