제출 #784446

#제출 시각아이디문제언어결과실행 시간메모리
784446tosivanmakFeast (NOI19_feast)C++17
71 / 100
365 ms26956 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double ll n,k; ld arr[300005]; pair<ld,ll> dp[300005][2]; ld dpval,lab; bool check(long double lambda) { dp[0][0] = {0, 0}, dp[0][1] = {-1e18, 0}; 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 + arr[i], dp[i - 1][1].second), make_pair(dp[i - 1][0].first + arr[i] - lambda, dp[i - 1][0].second + 1)); } return max(dp[n][0], dp[n][1]).second >= k; } ld Aliens(){ ld l=0,r=1e9*300000; while(r-l>=1e-4){ ld mid=(l+r)/2; if(check(mid)){ l=mid; } else{ r=mid; } } // cout<<dpval<<" "<<lab<<" "<<l<<"\n"; return max(dp[n][0],dp[n][1]).first+k*l; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n>>k; for(int i=1;i<=n;i++){ cin>>arr[i]; } ld ans=Aliens(); cout<<(long long)round(ans)<<"\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...