답안 #1103166

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1103166 2024-10-20T12:28:00 Z 0pt1mus23 Feast (NOI19_feast) C++14
41 / 100
32 ms 16464 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ins insert      
#define pb push_back
#define endl '\n'
#define putr(x) cout<<x<<endl;return; 
#define all(x) x.begin(),x.end()
// mt19937 rng(time(0));
const int mod = 1e9 +9, sze = 2e5 +23, inf = LLONG_MAX, LL = 30;
// Lagrangian Relaxation - Usaco Guide
pair<int,int> dp[2][sze];
int arr[sze];
int n;
void clc(int mid){
    dp[1][0]={arr[0]-mid,1}; 
    dp[0][0]={0,0};
    for(int i=1;i<n;i++){
        dp[0][i]=max(dp[0][i-1],dp[1][i-1]);
        dp[1][i]=max(
            make_pair(dp[0][i-1].first + arr[i]-mid,dp[0][i-1].second +1),
            make_pair(dp[1][i-1].first + arr[i],dp[1][i-1].second)
        );
    }    
}

void rush(){
    int k;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }

    int l =0;
    int r = 1e18;
    int ans=0;
    while(l<=r){
        int mid = (l+r)/2;
        clc(mid);
        auto mx = max(dp[1][n-1],dp[0][n-1]);
        if(mx.second >=k ){
            ans=mid;
            l=mid+1;
        }
        else{
            r = mid-1;
        }
    }

    clc(ans);
    auto mx = max(dp[1][n-1],dp[0][n-1]);
    putr( k*ans + mx.first );
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tt = 1;

    // cin>>tt;
    while(tt--){
        rush();
    }
 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 30 ms 16456 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 23 ms 16464 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 32 ms 16260 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4600 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4600 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4600 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4600 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4600 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4432 KB Output is correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 2 ms 4432 KB Output is correct
15 Correct 1 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 1 ms 4600 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 1 ms 4432 KB Output is correct
20 Correct 1 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4600 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4600 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4600 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4432 KB Output is correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 2 ms 4432 KB Output is correct
15 Correct 1 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 1 ms 4600 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 1 ms 4432 KB Output is correct
20 Correct 1 ms 4432 KB Output is correct
21 Correct 2 ms 4432 KB Output is correct
22 Correct 2 ms 4572 KB Output is correct
23 Correct 2 ms 4432 KB Output is correct
24 Correct 2 ms 4432 KB Output is correct
25 Correct 1 ms 4432 KB Output is correct
26 Correct 2 ms 4432 KB Output is correct
27 Correct 1 ms 4432 KB Output is correct
28 Correct 2 ms 4584 KB Output is correct
29 Correct 2 ms 4432 KB Output is correct
30 Correct 2 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 30 ms 16456 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -