답안 #1017614

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017614 2024-07-09T09:09:53 Z vjudge1 Feast (NOI19_feast) C++17
12 / 100
77 ms 12372 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define endl '\n'
#define ll long long
#define int long long
const long long inf=1e18;
const int MOD=998244353;
const int N=3e5+5;
int n,k,a[N];
pair<int,int> dp[N][2];
int func(int lambda){
    dp[0][0]={0,0};//empty
    dp[0][1]={-lambda,1};//using it
    for(int i=1;i<=n;i++){
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
        int x=dp[i-1][0].first-lambda+a[i],y=dp[i-1][1].first+a[i];
        if(x>y){
            dp[i][1].first=x;
            dp[i][1].second=dp[i-1][0].second+1;
        }
        else{
            dp[i][1].first=y;
            dp[i][1].second=dp[i-1][1].second;
        }
    }
    int x=dp[n][0].first,y=dp[n][1].first;
    if(x==y && dp[n][1]<dp[n][0])swap(dp[n][0],dp[n][1]);
    return (x>y?dp[n][0].second:dp[n][1].second);
}
signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>a[i];
    int l=0,r=1e18;
    while(l<r){
        int mid=(l+r+1)/2;
        int x=func(mid);
        if(x>=k)l=mid;
        else r=mid-1;
    }
    func(l);
    cout<<max(dp[n][0].first+l*dp[n][0].second,dp[n][1].first+l*dp[n][1].second);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 11856 KB Output is correct
2 Correct 51 ms 12124 KB Output is correct
3 Correct 50 ms 12164 KB Output is correct
4 Correct 51 ms 12160 KB Output is correct
5 Correct 50 ms 12088 KB Output is correct
6 Correct 49 ms 12104 KB Output is correct
7 Correct 49 ms 12120 KB Output is correct
8 Correct 51 ms 11940 KB Output is correct
9 Correct 50 ms 12120 KB Output is correct
10 Correct 50 ms 12140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 12124 KB Output is correct
2 Correct 59 ms 12372 KB Output is correct
3 Correct 43 ms 12120 KB Output is correct
4 Correct 55 ms 12124 KB Output is correct
5 Correct 68 ms 12104 KB Output is correct
6 Correct 41 ms 12124 KB Output is correct
7 Correct 43 ms 12124 KB Output is correct
8 Correct 56 ms 12120 KB Output is correct
9 Correct 48 ms 11864 KB Output is correct
10 Correct 55 ms 11976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 77 ms 12112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 11856 KB Output is correct
2 Correct 51 ms 12124 KB Output is correct
3 Correct 50 ms 12164 KB Output is correct
4 Correct 51 ms 12160 KB Output is correct
5 Correct 50 ms 12088 KB Output is correct
6 Correct 49 ms 12104 KB Output is correct
7 Correct 49 ms 12120 KB Output is correct
8 Correct 51 ms 11940 KB Output is correct
9 Correct 50 ms 12120 KB Output is correct
10 Correct 50 ms 12140 KB Output is correct
11 Correct 44 ms 12124 KB Output is correct
12 Correct 59 ms 12372 KB Output is correct
13 Correct 43 ms 12120 KB Output is correct
14 Correct 55 ms 12124 KB Output is correct
15 Correct 68 ms 12104 KB Output is correct
16 Correct 41 ms 12124 KB Output is correct
17 Correct 43 ms 12124 KB Output is correct
18 Correct 56 ms 12120 KB Output is correct
19 Correct 48 ms 11864 KB Output is correct
20 Correct 55 ms 11976 KB Output is correct
21 Incorrect 77 ms 12112 KB Output isn't correct
22 Halted 0 ms 0 KB -