Submission #962654

# Submission time Handle Problem Language Result Execution time Memory
962654 2024-04-14T06:22:06 Z biximo Feast (NOI19_feast) C++17
0 / 100
692 ms 23424 KB
#include <bits/stdc++.h>
#define N 300005
using namespace std;
typedef pair<long double, int> pi;
pi DP[N][2];
int n, k, seq[N];
int doDP(long double pen) {
	for(auto&i: DP) for(auto&j: i) j = make_pair(-9e18,0);
	DP[0][0] = {0,0};
	for(int i = 1; i <= n+1; i ++) {
		DP[i][0] = max(DP[i-1][0], DP[i-1][1]);
		DP[i][1] = max(DP[i-1][1], make_pair(DP[i-1][0].first-pen, DP[i-1][0].second+1));
		DP[i][1].first += seq[i];
	}
	return DP[n+1][0].second;
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> k;
    int pc = 0;
    for(int i = 1; i <= n; i ++) {
    	cin >> seq[i];
    	if(seq[i] > 0 && seq[i-1] <= 0) pc ++;
    }
    k = min(k, pc);
    long double l=0,h=1e13;
    for(int i = 0; i < 100; i ++) {
    	long double m = (l+h)/2;
    	int res = doDP(m);
    	if(res > k) {
    		l = m;
    	} else {
    		h = m;
    	}
    }
    cout << round(DP[n+1][0].first + k*l);
}
# Verdict Execution time Memory Grader output
1 Incorrect 649 ms 23192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 644 ms 21328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 692 ms 23424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 261 ms 20056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 261 ms 20056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 261 ms 20056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 649 ms 23192 KB Output isn't correct
2 Halted 0 ms 0 KB -