답안 #1017453

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017453 2024-07-09T08:07:55 Z hehebjp123 Feast (NOI19_feast) C++14
4 / 100
94 ms 10328 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=1e15,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 75 ms 10064 KB Output is correct
2 Correct 64 ms 10252 KB Output is correct
3 Correct 66 ms 10320 KB Output is correct
4 Correct 94 ms 10176 KB Output is correct
5 Correct 66 ms 10048 KB Output is correct
6 Correct 84 ms 10068 KB Output is correct
7 Correct 63 ms 10072 KB Output is correct
8 Correct 64 ms 10068 KB Output is correct
9 Correct 62 ms 10076 KB Output is correct
10 Correct 66 ms 10196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 51 ms 8296 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 64 ms 10328 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 75 ms 10064 KB Output is correct
2 Correct 64 ms 10252 KB Output is correct
3 Correct 66 ms 10320 KB Output is correct
4 Correct 94 ms 10176 KB Output is correct
5 Correct 66 ms 10048 KB Output is correct
6 Correct 84 ms 10068 KB Output is correct
7 Correct 63 ms 10072 KB Output is correct
8 Correct 64 ms 10068 KB Output is correct
9 Correct 62 ms 10076 KB Output is correct
10 Correct 66 ms 10196 KB Output is correct
11 Incorrect 51 ms 8296 KB Output isn't correct
12 Halted 0 ms 0 KB -