Submission #942032

# Submission time Handle Problem Language Result Execution time Memory
942032 2024-03-10T03:58:10 Z 8pete8 Feast (NOI19_feast) C++17
100 / 100
117 ms 15208 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include <cassert>
#include <cstdint>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
using namespace std;
#define int long long
#define double long double
const int mod=1e9+7,mxn=3e5+5,lg=30,inf=1e16,minf=-1e18;
int v[mxn+10],mid;
pii dp[mxn+10][2];
int n,m;
int check(){
	dp[0][0]={0,0};
	dp[0][1]={minf,0};
	for(int i=1;i<=n;i++){
		dp[i][0]=max(dp[i-1][1],dp[i-1][0]);
		dp[i][1]=max(make_pair(dp[i-1][1].f+v[i],dp[i-1][1].s),make_pair(dp[i-1][0].f+v[i]-mid,dp[i-1][0].s+1));
	}
	return max(dp[n][0],dp[n][1]).s;
}
int32_t main(){
    fastio
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>v[i];
	int l=0,r=inf;
	int ans=inf;
	while(l<=r){
		mid=l+(r-l)/2;
		if(check()<=m)r=mid-1,ans=mid;
		else l=mid+1;
	}
	mid=ans;
	check();
	cout<<(m*ans)+max(dp[n][0].f,dp[n][1].f);
	/*
	lambda increase 
	group decrease
	*/
}
/*
*/
# Verdict Execution time Memory Grader output
1 Correct 75 ms 14672 KB Output is correct
2 Correct 79 ms 14940 KB Output is correct
3 Correct 78 ms 14940 KB Output is correct
4 Correct 78 ms 14872 KB Output is correct
5 Correct 79 ms 15000 KB Output is correct
6 Correct 77 ms 14908 KB Output is correct
7 Correct 80 ms 14904 KB Output is correct
8 Correct 78 ms 15004 KB Output is correct
9 Correct 77 ms 14672 KB Output is correct
10 Correct 78 ms 14912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 13236 KB Output is correct
2 Correct 69 ms 13308 KB Output is correct
3 Correct 67 ms 13148 KB Output is correct
4 Correct 67 ms 13136 KB Output is correct
5 Correct 77 ms 14912 KB Output is correct
6 Correct 67 ms 13228 KB Output is correct
7 Correct 69 ms 13124 KB Output is correct
8 Correct 80 ms 14940 KB Output is correct
9 Correct 78 ms 14684 KB Output is correct
10 Correct 68 ms 13148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 15184 KB Output is correct
2 Correct 85 ms 14936 KB Output is correct
3 Correct 85 ms 14940 KB Output is correct
4 Correct 84 ms 15108 KB Output is correct
5 Correct 86 ms 14928 KB Output is correct
6 Correct 86 ms 15108 KB Output is correct
7 Correct 86 ms 15184 KB Output is correct
8 Correct 85 ms 15156 KB Output is correct
9 Correct 91 ms 15184 KB Output is correct
10 Correct 87 ms 15208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2516 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2516 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2516 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2540 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2544 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 14672 KB Output is correct
2 Correct 79 ms 14940 KB Output is correct
3 Correct 78 ms 14940 KB Output is correct
4 Correct 78 ms 14872 KB Output is correct
5 Correct 79 ms 15000 KB Output is correct
6 Correct 77 ms 14908 KB Output is correct
7 Correct 80 ms 14904 KB Output is correct
8 Correct 78 ms 15004 KB Output is correct
9 Correct 77 ms 14672 KB Output is correct
10 Correct 78 ms 14912 KB Output is correct
11 Correct 75 ms 13236 KB Output is correct
12 Correct 69 ms 13308 KB Output is correct
13 Correct 67 ms 13148 KB Output is correct
14 Correct 67 ms 13136 KB Output is correct
15 Correct 77 ms 14912 KB Output is correct
16 Correct 67 ms 13228 KB Output is correct
17 Correct 69 ms 13124 KB Output is correct
18 Correct 80 ms 14940 KB Output is correct
19 Correct 78 ms 14684 KB Output is correct
20 Correct 68 ms 13148 KB Output is correct
21 Correct 89 ms 15184 KB Output is correct
22 Correct 85 ms 14936 KB Output is correct
23 Correct 85 ms 14940 KB Output is correct
24 Correct 84 ms 15108 KB Output is correct
25 Correct 86 ms 14928 KB Output is correct
26 Correct 86 ms 15108 KB Output is correct
27 Correct 86 ms 15184 KB Output is correct
28 Correct 85 ms 15156 KB Output is correct
29 Correct 91 ms 15184 KB Output is correct
30 Correct 87 ms 15208 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2516 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2392 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2392 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 1 ms 2540 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 1 ms 2544 KB Output is correct
59 Correct 1 ms 2396 KB Output is correct
60 Correct 1 ms 2396 KB Output is correct
61 Correct 111 ms 15096 KB Output is correct
62 Correct 108 ms 15184 KB Output is correct
63 Correct 94 ms 14852 KB Output is correct
64 Correct 112 ms 15188 KB Output is correct
65 Correct 117 ms 15056 KB Output is correct
66 Correct 117 ms 14940 KB Output is correct
67 Correct 113 ms 14932 KB Output is correct
68 Correct 86 ms 15120 KB Output is correct
69 Correct 87 ms 15096 KB Output is correct
70 Correct 84 ms 14932 KB Output is correct