제출 #1017306

#제출 시각아이디문제언어결과실행 시간메모리
1017306thdh__Feast (NOI19_feast)C++17
100 / 100
147 ms12124 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,fma") #define ll long long #define pb push_back #define eb emplace_back #define pu push #define ins insert #define bruh ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define ff(x,a,b,c) for (auto x=a;x<=b;x+=c) #define fd(x,a,b,c) for (auto x=a;x>=b;x-=c) #define int ll using namespace std; //mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); typedef pair<int, int> ii; const int N = 3e5+5; const int mod = 1e9+7; const int INF = 1e18; int power(int a,int b) {ll x = 1;if (a >= mod) a%=mod; while (b) {if (b & 1) x = x*a % mod;a = a*a % mod;b>>=1;}return x;} int n,k; int a[N]; pair<int,int> calc(int lmb) { pair<int,int> dp[n][2]; dp[0][0] = {0,0}; dp[0][1] = {a[0]-lmb,1}; for (int i=1;i<n;i++) { dp[i][0] = max(dp[i-1][0],dp[i-1][1]); dp[i][1] = max(make_pair(dp[i-1][1].first+a[i],dp[i-1][1].second),make_pair(dp[i-1][0].first+a[i]-lmb,dp[i-1][0].second+1)); } return max(dp[n-1][0],dp[n-1][1]); } void solve() { cin>>n>>k; for (int i=0;i<n;i++) cin>>a[i]; int l = 0,r = 1e18,ans = 0; while (l<=r) { int mid = (l+r)/2; auto tmp = calc(mid); if (tmp.second>=k) l = mid+1,ans = mid; else r = mid-1; } //cout<<ans<<endl; cout<<calc(ans).first+ans*k; } signed main() { bruh //freopen("input.inp","r",stdin); //freopen("output.inp","w",stdout); int t = 1; //cin>>t; while (t--) { solve(); cout<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...