답안 #817799

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
817799 2023-08-09T16:33:16 Z vjudge1 Feast (NOI19_feast) C++17
18 / 100
239 ms 17544 KB
#include <bits/stdc++.h>
using namespace std;

void main_program();

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	main_program();
}

#define int long long

using ii = pair<int, int>;

int n, k;
vector<int> v, pfx;

ii better(ii a, ii b){
	if (a.first != b.first){
		return (a.first > b.first) ? a : b;
	}
	return (a.second < b.second) ? a : b;
}

ii f(int lambda){
	vector<ii> dp_closed(n+1), dp_open(n+1);
	dp_closed[0] = {0, 0};
	dp_open[0] = {0, 0};

	for (int i = 1; i <= n; i++){
		dp_closed[i] = better(dp_closed[i-1],
			{dp_open[i-1].first + pfx[i] - lambda, dp_open[i-1].second + 1});
		dp_open[i] = better(dp_open[i-1],
			{dp_closed[i].first - pfx[i-1], dp_closed[i].second});
	}

	return dp_closed[n];
}

void main_program(){
	cin >> n >> k;

	v.resize(n+1);
	for (int i = 1; i <= n; i++) cin >> v[i];
	pfx = v;
	for (int i = 1; i <= n; i++) pfx[i] += pfx[i-1];

	int l = 0, r = 3e14;
	while (l < r){
		int mid = (l + r) >> 1;
		auto res = f(mid);
		if (res.second <= k) r = mid;
		else l = mid + 1;
	}

	auto res = f(l);
	cout << res.first + l * res.second << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 205 ms 16872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 207 ms 15308 KB Output is correct
2 Correct 215 ms 15636 KB Output is correct
3 Correct 192 ms 15388 KB Output is correct
4 Incorrect 203 ms 15476 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 212 ms 17408 KB Output is correct
2 Correct 239 ms 17172 KB Output is correct
3 Correct 201 ms 17364 KB Output is correct
4 Correct 203 ms 17216 KB Output is correct
5 Correct 219 ms 17412 KB Output is correct
6 Correct 208 ms 17500 KB Output is correct
7 Correct 218 ms 17504 KB Output is correct
8 Correct 216 ms 17544 KB Output is correct
9 Correct 233 ms 17512 KB Output is correct
10 Correct 203 ms 17492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Incorrect 1 ms 320 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Incorrect 1 ms 320 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Incorrect 1 ms 320 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 205 ms 16872 KB Output isn't correct
2 Halted 0 ms 0 KB -