답안 #1085261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1085261 2024-09-07T19:07:23 Z quan606303 Feast (NOI19_feast) C++14
40 / 100
95 ms 17492 KB
///0-0 : what is your motivation, quan606303?
///quan606303 : Hutao
/*idea : 



*/
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define INTMAX INT_MAX
#define INTMIN INT_MIN
#define LONGMAX LLONG_MAX
#define LONGMIN LLONG_MIN
#define fi first
#define se second
#define memfull(a,b) memset(a,b,sizeof(a));
#define endl '\n'
#define file(a) freopen(a".inp","r",stdin); freopen(a".out","w",stdout);
using namespace std;
const int MOD=1e9+7;
const int maxn=3e5+7;;
int n,k,a[maxn],pre[maxn];
pair<int,int> dp[maxn][2];
pair<int,int> sub1(int pen)
{
    dp[1][0]={0,0};
    dp[1][1]={-pre[0]-pen,1};
    for (int i=2;i<=n;i++)
    {
        dp[i][1]=max(dp[i-1][1],make_pair(dp[i-1][0].fi-pre[i-1]-pen,dp[i-1][0].se+1));
        dp[i][0]=max(dp[i-1][0],make_pair(dp[i][1].fi+pre[i],dp[i][1].se));
    }
    return dp[n][0];
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   // file("MUABANCO");
    cin>>n>>k;
    for (int i=1;i<=n;i++)cin>>a[i];
    for (int i=1;i<=n;i++)pre[i]=pre[i-1]+a[i];
    int l=0,r=1e18,ans=0;
    while (l<=r)
    {
        int mid=(l+r)/2;
        pair<int,int> cnt=sub1(mid);
        if (cnt.se<=k)
        {
            r=mid-1;
            ans=cnt.fi+cnt.se*mid;
        }
        else l=mid+1;
    }
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 16636 KB Output is correct
2 Correct 65 ms 17036 KB Output is correct
3 Correct 67 ms 17236 KB Output is correct
4 Correct 68 ms 17276 KB Output is correct
5 Correct 65 ms 16976 KB Output is correct
6 Correct 62 ms 16908 KB Output is correct
7 Correct 63 ms 16732 KB Output is correct
8 Correct 64 ms 17164 KB Output is correct
9 Correct 69 ms 16728 KB Output is correct
10 Correct 65 ms 17048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 15196 KB Output is correct
2 Correct 72 ms 15436 KB Output is correct
3 Correct 56 ms 15196 KB Output is correct
4 Correct 67 ms 15184 KB Output is correct
5 Correct 67 ms 16724 KB Output is correct
6 Correct 56 ms 15448 KB Output is correct
7 Correct 58 ms 15664 KB Output is correct
8 Correct 64 ms 17240 KB Output is correct
9 Correct 64 ms 16724 KB Output is correct
10 Correct 57 ms 15448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 17240 KB Output is correct
2 Correct 89 ms 17168 KB Output is correct
3 Correct 85 ms 17240 KB Output is correct
4 Correct 88 ms 16976 KB Output is correct
5 Correct 90 ms 17240 KB Output is correct
6 Correct 95 ms 17448 KB Output is correct
7 Correct 89 ms 17488 KB Output is correct
8 Correct 93 ms 17492 KB Output is correct
9 Correct 85 ms 17412 KB Output is correct
10 Correct 85 ms 17488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 356 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 356 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Incorrect 1 ms 344 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 356 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Incorrect 1 ms 344 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 16636 KB Output is correct
2 Correct 65 ms 17036 KB Output is correct
3 Correct 67 ms 17236 KB Output is correct
4 Correct 68 ms 17276 KB Output is correct
5 Correct 65 ms 16976 KB Output is correct
6 Correct 62 ms 16908 KB Output is correct
7 Correct 63 ms 16732 KB Output is correct
8 Correct 64 ms 17164 KB Output is correct
9 Correct 69 ms 16728 KB Output is correct
10 Correct 65 ms 17048 KB Output is correct
11 Correct 56 ms 15196 KB Output is correct
12 Correct 72 ms 15436 KB Output is correct
13 Correct 56 ms 15196 KB Output is correct
14 Correct 67 ms 15184 KB Output is correct
15 Correct 67 ms 16724 KB Output is correct
16 Correct 56 ms 15448 KB Output is correct
17 Correct 58 ms 15664 KB Output is correct
18 Correct 64 ms 17240 KB Output is correct
19 Correct 64 ms 16724 KB Output is correct
20 Correct 57 ms 15448 KB Output is correct
21 Correct 88 ms 17240 KB Output is correct
22 Correct 89 ms 17168 KB Output is correct
23 Correct 85 ms 17240 KB Output is correct
24 Correct 88 ms 16976 KB Output is correct
25 Correct 90 ms 17240 KB Output is correct
26 Correct 95 ms 17448 KB Output is correct
27 Correct 89 ms 17488 KB Output is correct
28 Correct 93 ms 17492 KB Output is correct
29 Correct 85 ms 17412 KB Output is correct
30 Correct 85 ms 17488 KB Output is correct
31 Correct 0 ms 356 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Incorrect 1 ms 344 KB Output isn't correct
42 Halted 0 ms 0 KB -