답안 #1017455

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017455 2024-07-09T08:08:53 Z hehebjp123 Feast (NOI19_feast) C++14
4 / 100
73 ms 10044 KB
#include <bits/stdc++.h>
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define pb push_back
using namespace std;
const ll N=3e5+9;
const ll mod=1e9+7;
    ll t,n,k,i,m,x,a[N],tot[N],q,l,b[N],c[N],mu[N],sl=0,xor_basis[64],len=0,r;
ll dp[N][2];
ii check(ll pen)
{
    dp[0][1]=-pen;
    dp[0][0]=0;
    ll res=0;
    ll cnt=0;
    for(i=1;i<=n;i++)
    {
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
        dp[i][1]=max(dp[i-1][0]-pen,dp[i-1][1])+a[i];
        res=max(res,dp[i][1]);
    }
    bool op=0;
    ll tot=res;
    if(res==0) return {0,0};
    for(i=n;i>0;i--)
    if(res==dp[i][1])
    {
        res-=a[i];
        if(!op){res-=pen; cnt++;}
        op=1;
    }
        return {tot+pen*cnt,cnt};
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
cin>>n>>k;
for(i=1;i<=n;i++)
    cin>>a[i];
ll l=0,r=1e18,kq=0;
while(l<=r)
{
    ll mid=(l+r)/2;
    ii ans=check(mid);
  //  cout<<mid<<" "<<ans.se<<'\n';
    if(ans.se<=k){
            if(ans.se>0)
        kq=max(kq,ans.fi);
        r=mid-1;
    }
    else l=mid+1;
}
cout<<kq;
}
/*
6 2
1 2 3 -10 5 6

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 9556 KB Output is correct
2 Correct 70 ms 9808 KB Output is correct
3 Correct 71 ms 10044 KB Output is correct
4 Correct 71 ms 9860 KB Output is correct
5 Correct 64 ms 9808 KB Output is correct
6 Correct 69 ms 9544 KB Output is correct
7 Correct 73 ms 9376 KB Output is correct
8 Correct 70 ms 9972 KB Output is correct
9 Correct 69 ms 9588 KB Output is correct
10 Correct 69 ms 9808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 8280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 72 ms 9812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 9556 KB Output is correct
2 Correct 70 ms 9808 KB Output is correct
3 Correct 71 ms 10044 KB Output is correct
4 Correct 71 ms 9860 KB Output is correct
5 Correct 64 ms 9808 KB Output is correct
6 Correct 69 ms 9544 KB Output is correct
7 Correct 73 ms 9376 KB Output is correct
8 Correct 70 ms 9972 KB Output is correct
9 Correct 69 ms 9588 KB Output is correct
10 Correct 69 ms 9808 KB Output is correct
11 Incorrect 63 ms 8280 KB Output isn't correct
12 Halted 0 ms 0 KB -