이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAX = 3e5 + 5;
int n, k, A[MAX]; pair<ll, ll> dp[MAX][2];
pair<ll, ll> better(pair<ll, ll> a, pair<ll, ll> b){
if (a.first == b.first)
return (a.second < b.second ? a : b);
return (a.first > b.first ? a : b);
}
bool solve(ll lmb){
dp[0][0] = {0, 0};
dp[0][1] = {-1e18, 0};
for (int i = 1; i <= n; i++){
dp[i][0] = better(dp[i - 1][0], dp[i - 1][1]);
dp[i][1] = better(
{dp[i - 1][0].first + A[i] - lmb, dp[i - 1][0].second + 1},
{dp[i - 1][1].first + A[i], dp[i - 1][1].second}
);
}
return better(dp[n][0], dp[n][1]).second <= k;
}
int main(){
ios_base::sync_with_stdio; cin.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> A[i];
ll L = 0, H = 1e15;
while (L < H){
ll M = (L + H) / 2;
solve(M) ? H = M : L = M + 1;
}
solve(L);
cout << better(dp[n][0], dp[n][1]).first + L * k << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
feast.cpp: In function 'int main()':
feast.cpp:33:15: warning: statement is a reference, not call, to function 'std::ios_base::sync_with_stdio' [-Waddress]
33 | ios_base::sync_with_stdio; cin.tie(0);
| ~~~~~~~~~~^~~~~~~~~~~~~~~
feast.cpp:33:15: warning: statement has no effect [-Wunused-value]
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |