# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1026011 | 2024-07-17T12:33:07 Z | fv3 | Feast (NOI19_feast) | C++17 | 35 ms | 7896 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<ll> a, b; ll res; ll solve(ll pun) { res = 0; ll last = -pun; ll seg_cnt = 0; for (auto n : b) { if (n > 0) last += n; else if (n < -pun) { res += last; if (last > 0) seg_cnt++; last = -pun; } else { last += n; } if (last < -pun) last = -pun; //cerr << last << ' ' << res << '\n'; } if (last > 0) { res += last; seg_cnt++; } return seg_cnt; } int main() { ios::sync_with_stdio(0); cin.tie(0); ll N, K; cin >> N >> K; a = vector<ll>(N); for (int i = 0; i < N; i++) cin >> a[i]; { ll sum = a[0]; for (int i = 1; i < N; i++) { if ((a[i-1] ^ a[i]) < 0) { b.push_back(sum); sum = 0; } sum += a[i]; } if (sum != 0) b.push_back(sum); } ll l = 0; ll r = 1e18; while (l < r) { ll c = (l + r) / 2ll; if (solve(c) > K) l = c + 1; else r = c; } ll seg_cnt = solve(l); cout << res + K * l << '\n'; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 5464 KB | Output is correct |
2 | Correct | 21 ms | 5468 KB | Output is correct |
3 | Correct | 25 ms | 5616 KB | Output is correct |
4 | Correct | 20 ms | 5464 KB | Output is correct |
5 | Correct | 20 ms | 5460 KB | Output is correct |
6 | Correct | 20 ms | 5468 KB | Output is correct |
7 | Correct | 20 ms | 5468 KB | Output is correct |
8 | Correct | 20 ms | 5592 KB | Output is correct |
9 | Correct | 20 ms | 5468 KB | Output is correct |
10 | Correct | 24 ms | 5552 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 3676 KB | Output is correct |
2 | Correct | 13 ms | 3932 KB | Output is correct |
3 | Correct | 13 ms | 3632 KB | Output is correct |
4 | Correct | 13 ms | 3676 KB | Output is correct |
5 | Correct | 20 ms | 5468 KB | Output is correct |
6 | Correct | 13 ms | 3676 KB | Output is correct |
7 | Correct | 13 ms | 3824 KB | Output is correct |
8 | Correct | 20 ms | 5468 KB | Output is correct |
9 | Correct | 23 ms | 5468 KB | Output is correct |
10 | Correct | 13 ms | 3928 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 35 ms | 7896 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 | 20 ms | 5464 KB | Output is correct |
2 | Correct | 21 ms | 5468 KB | Output is correct |
3 | Correct | 25 ms | 5616 KB | Output is correct |
4 | Correct | 20 ms | 5464 KB | Output is correct |
5 | Correct | 20 ms | 5460 KB | Output is correct |
6 | Correct | 20 ms | 5468 KB | Output is correct |
7 | Correct | 20 ms | 5468 KB | Output is correct |
8 | Correct | 20 ms | 5592 KB | Output is correct |
9 | Correct | 20 ms | 5468 KB | Output is correct |
10 | Correct | 24 ms | 5552 KB | Output is correct |
11 | Correct | 15 ms | 3676 KB | Output is correct |
12 | Correct | 13 ms | 3932 KB | Output is correct |
13 | Correct | 13 ms | 3632 KB | Output is correct |
14 | Correct | 13 ms | 3676 KB | Output is correct |
15 | Correct | 20 ms | 5468 KB | Output is correct |
16 | Correct | 13 ms | 3676 KB | Output is correct |
17 | Correct | 13 ms | 3824 KB | Output is correct |
18 | Correct | 20 ms | 5468 KB | Output is correct |
19 | Correct | 23 ms | 5468 KB | Output is correct |
20 | Correct | 13 ms | 3928 KB | Output is correct |
21 | Incorrect | 35 ms | 7896 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |