이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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];
bool check(long double lambda) {
dp[0][0] = {0, 0}, dp[0][1] = {-300000*1e9, 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<<(ll)round(ans)<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |