답안 #1085240

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1085240 2024-09-07T17:59:23 Z quan606303 Feast (NOI19_feast) C++11
100 / 100
119 ms 15240 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;
pair<int,int> dp[maxn][2];
int a[maxn],n,k;
pair<int,int> solve(int pen)
{
    dp[1][0]={0,0};
    dp[1][1]={a[1]-pen,1};
    for (int i=2;i<=n;i++)
    {
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
        dp[i][1]=max(make_pair(dp[i-1][0].fi+a[i]-pen,dp[i-1][0].se+1),make_pair(dp[i-1][1].fi+a[i],dp[i-1][1].se));
    }
    return max(dp[n][0],dp[n][1]);
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  //  file("");
    cin>>n>>k;
    for (int i=1;i<=n;i++)cin>>a[i];
    int l=0,r=1e18,ans=0;
    while (l<=r)
    {
        int mid=(l+r)/2;
        pair<int,int> cnt=solve(mid);
        if (cnt.se<=k)
        {
            ans=cnt.fi+cnt.se*mid;
            r=mid-1;
        }
        else l=mid+1;
    }
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 14608 KB Output is correct
2 Correct 57 ms 14832 KB Output is correct
3 Correct 57 ms 14932 KB Output is correct
4 Correct 57 ms 14928 KB Output is correct
5 Correct 57 ms 14872 KB Output is correct
6 Correct 56 ms 14420 KB Output is correct
7 Correct 55 ms 14496 KB Output is correct
8 Correct 59 ms 14676 KB Output is correct
9 Correct 56 ms 14416 KB Output is correct
10 Correct 56 ms 14676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 12892 KB Output is correct
2 Correct 50 ms 13144 KB Output is correct
3 Correct 48 ms 12892 KB Output is correct
4 Correct 48 ms 12888 KB Output is correct
5 Correct 56 ms 14416 KB Output is correct
6 Correct 49 ms 12888 KB Output is correct
7 Correct 50 ms 13144 KB Output is correct
8 Correct 58 ms 14944 KB Output is correct
9 Correct 55 ms 14424 KB Output is correct
10 Correct 49 ms 13232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 14932 KB Output is correct
2 Correct 82 ms 14896 KB Output is correct
3 Correct 81 ms 14932 KB Output is correct
4 Correct 89 ms 14844 KB Output is correct
5 Correct 81 ms 14936 KB Output is correct
6 Correct 88 ms 14928 KB Output is correct
7 Correct 85 ms 14968 KB Output is correct
8 Correct 99 ms 15208 KB Output is correct
9 Correct 84 ms 15144 KB Output is correct
10 Correct 85 ms 15184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 476 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 14608 KB Output is correct
2 Correct 57 ms 14832 KB Output is correct
3 Correct 57 ms 14932 KB Output is correct
4 Correct 57 ms 14928 KB Output is correct
5 Correct 57 ms 14872 KB Output is correct
6 Correct 56 ms 14420 KB Output is correct
7 Correct 55 ms 14496 KB Output is correct
8 Correct 59 ms 14676 KB Output is correct
9 Correct 56 ms 14416 KB Output is correct
10 Correct 56 ms 14676 KB Output is correct
11 Correct 48 ms 12892 KB Output is correct
12 Correct 50 ms 13144 KB Output is correct
13 Correct 48 ms 12892 KB Output is correct
14 Correct 48 ms 12888 KB Output is correct
15 Correct 56 ms 14416 KB Output is correct
16 Correct 49 ms 12888 KB Output is correct
17 Correct 50 ms 13144 KB Output is correct
18 Correct 58 ms 14944 KB Output is correct
19 Correct 55 ms 14424 KB Output is correct
20 Correct 49 ms 13232 KB Output is correct
21 Correct 85 ms 14932 KB Output is correct
22 Correct 82 ms 14896 KB Output is correct
23 Correct 81 ms 14932 KB Output is correct
24 Correct 89 ms 14844 KB Output is correct
25 Correct 81 ms 14936 KB Output is correct
26 Correct 88 ms 14928 KB Output is correct
27 Correct 85 ms 14968 KB Output is correct
28 Correct 99 ms 15208 KB Output is correct
29 Correct 84 ms 15144 KB Output is correct
30 Correct 85 ms 15184 KB Output is correct
31 Correct 0 ms 344 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 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 476 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 118 ms 14932 KB Output is correct
62 Correct 109 ms 15240 KB Output is correct
63 Correct 94 ms 14672 KB Output is correct
64 Correct 118 ms 14928 KB Output is correct
65 Correct 116 ms 14928 KB Output is correct
66 Correct 119 ms 14928 KB Output is correct
67 Correct 116 ms 14672 KB Output is correct
68 Correct 84 ms 14928 KB Output is correct
69 Correct 83 ms 14840 KB Output is correct
70 Correct 81 ms 14676 KB Output is correct