답안 #1017410

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017410 2024-07-09T07:48:18 Z vjudge1 Feast (NOI19_feast) C++17
100 / 100
107 ms 12132 KB
#include<bits/stdc++.h>

using namespace std;
#define int long long
pair<int, int> dp[300005][2];
int n, k, a[300005];
pair<int, int> sigma(int cost) {
    dp[0][1] = {-1e18, 0};
    for (int i = 1; i <= n; i++) {
        dp[i][0] = max(dp[i-1][0], dp[i-1][1]);
        pair<int,int> v1 = {dp[i-1][1].first+a[i],dp[i-1][1].second};
        pair<int,int> v2 = {dp[i-1][0].first+a[i]-cost, dp[i-1][0].second+1};
        dp[i][1] = (v1.first > v2.first ? v1 : v2);
        //if(cost == 2) cout << i << ' ' << dp[i][0].first << ' ' << dp[i][0].second << ' ' << dp[i][1].first << ' ' << dp[i][1].second << '\n';
    }
    return max(dp[n][0], dp[n][1]);
}
void solve() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int l = 0, r = 3e14, mid, ans=0;
    while(l <= r) {
        mid = (l + r) / 2;
        pair<int, int> val = sigma(mid);
        if(val.second <= k) {
           // cout << mid << ' ' << val.first << ' ' << val.second << '\n';
            ans = max(ans, val.first + mid * val.second);
            r = mid-1;
        }
        else l = mid+1;
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(fopen("input.inp","r")){
        freopen("input.inp", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int t = 1;
    // cin >> t;
    while(t--) {
        solve();
    }
}

Compilation message

feast.cpp: In function 'int main()':
feast.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen("input.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen("output.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 11868 KB Output is correct
2 Correct 49 ms 11868 KB Output is correct
3 Correct 49 ms 12112 KB Output is correct
4 Correct 63 ms 12100 KB Output is correct
5 Correct 48 ms 11868 KB Output is correct
6 Correct 47 ms 11660 KB Output is correct
7 Correct 46 ms 11856 KB Output is correct
8 Correct 48 ms 11864 KB Output is correct
9 Correct 48 ms 11864 KB Output is correct
10 Correct 48 ms 12008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 11868 KB Output is correct
2 Correct 42 ms 12124 KB Output is correct
3 Correct 41 ms 11932 KB Output is correct
4 Correct 42 ms 11864 KB Output is correct
5 Correct 59 ms 11864 KB Output is correct
6 Correct 45 ms 11868 KB Output is correct
7 Correct 43 ms 12120 KB Output is correct
8 Correct 48 ms 11860 KB Output is correct
9 Correct 58 ms 11856 KB Output is correct
10 Correct 42 ms 12124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 11864 KB Output is correct
2 Correct 67 ms 11856 KB Output is correct
3 Correct 67 ms 11868 KB Output is correct
4 Correct 66 ms 11856 KB Output is correct
5 Correct 66 ms 12040 KB Output is correct
6 Correct 75 ms 11908 KB Output is correct
7 Correct 69 ms 12132 KB Output is correct
8 Correct 67 ms 11868 KB Output is correct
9 Correct 67 ms 12124 KB Output is correct
10 Correct 67 ms 12124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 0 ms 424 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 0 ms 424 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 0 ms 424 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 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 2396 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 49 ms 11868 KB Output is correct
2 Correct 49 ms 11868 KB Output is correct
3 Correct 49 ms 12112 KB Output is correct
4 Correct 63 ms 12100 KB Output is correct
5 Correct 48 ms 11868 KB Output is correct
6 Correct 47 ms 11660 KB Output is correct
7 Correct 46 ms 11856 KB Output is correct
8 Correct 48 ms 11864 KB Output is correct
9 Correct 48 ms 11864 KB Output is correct
10 Correct 48 ms 12008 KB Output is correct
11 Correct 41 ms 11868 KB Output is correct
12 Correct 42 ms 12124 KB Output is correct
13 Correct 41 ms 11932 KB Output is correct
14 Correct 42 ms 11864 KB Output is correct
15 Correct 59 ms 11864 KB Output is correct
16 Correct 45 ms 11868 KB Output is correct
17 Correct 43 ms 12120 KB Output is correct
18 Correct 48 ms 11860 KB Output is correct
19 Correct 58 ms 11856 KB Output is correct
20 Correct 42 ms 12124 KB Output is correct
21 Correct 75 ms 11864 KB Output is correct
22 Correct 67 ms 11856 KB Output is correct
23 Correct 67 ms 11868 KB Output is correct
24 Correct 66 ms 11856 KB Output is correct
25 Correct 66 ms 12040 KB Output is correct
26 Correct 75 ms 11908 KB Output is correct
27 Correct 69 ms 12132 KB Output is correct
28 Correct 67 ms 11868 KB Output is correct
29 Correct 67 ms 12124 KB Output is correct
30 Correct 67 ms 12124 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 0 ms 424 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 0 ms 2396 KB Output is correct
40 Correct 0 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 2396 KB Output is correct
45 Correct 0 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 2396 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 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 2396 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 100 ms 11856 KB Output is correct
62 Correct 101 ms 12120 KB Output is correct
63 Correct 85 ms 11856 KB Output is correct
64 Correct 107 ms 12120 KB Output is correct
65 Correct 104 ms 11868 KB Output is correct
66 Correct 101 ms 12068 KB Output is correct
67 Correct 103 ms 11924 KB Output is correct
68 Correct 75 ms 12116 KB Output is correct
69 Correct 67 ms 11864 KB Output is correct
70 Correct 66 ms 11648 KB Output is correct