답안 #1017478

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017478 2024-07-09T08:18:25 Z hehebjp123 Feast (NOI19_feast) C++14
4 / 100
79 ms 7476 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++;}
        //if(res==0) break;
        op=1;
    }
    else op=0;
        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 67 ms 7264 KB Output is correct
2 Correct 79 ms 7252 KB Output is correct
3 Correct 70 ms 7476 KB Output is correct
4 Correct 69 ms 7260 KB Output is correct
5 Correct 69 ms 7252 KB Output is correct
6 Correct 70 ms 7248 KB Output is correct
7 Correct 68 ms 7260 KB Output is correct
8 Correct 68 ms 7360 KB Output is correct
9 Correct 69 ms 7072 KB Output is correct
10 Correct 70 ms 7260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 60 ms 7312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 71 ms 7408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 7264 KB Output is correct
2 Correct 79 ms 7252 KB Output is correct
3 Correct 70 ms 7476 KB Output is correct
4 Correct 69 ms 7260 KB Output is correct
5 Correct 69 ms 7252 KB Output is correct
6 Correct 70 ms 7248 KB Output is correct
7 Correct 68 ms 7260 KB Output is correct
8 Correct 68 ms 7360 KB Output is correct
9 Correct 69 ms 7072 KB Output is correct
10 Correct 70 ms 7260 KB Output is correct
11 Incorrect 60 ms 7312 KB Output isn't correct
12 Halted 0 ms 0 KB -