Submission #376859

#TimeUsernameProblemLanguageResultExecution timeMemory
3768592qbingxuanCake 3 (JOI19_cake3)C++14
0 / 100
1 ms364 KiB
#include <bits/stdc++.h> #ifdef local #define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n" #define debug(a...) qqbx(#a, a) template <typename ...T> void qqbx(const char *s, T ...a) { int cnt = sizeof...(T); ((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : "\033[0m)\n"))); } #else #define debug(...) ((void)0) #define safe ((void)0) #endif // local #define all(v) begin(v),end(v) using namespace std; const int64_t INF = 1e18; signed main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, m; cin >> n >> m; vector<pair<int64_t,int64_t>> cake(n); for (auto &[c, v]: cake) cin >> v >> c; sort(all(cake)); auto calc = [&](int cost) -> pair<int64_t, int64_t> { pair<int64_t, int64_t> dp[3]; dp[0] = {0, 0}; dp[1] = dp[2] = {-INF, -INF}; for (auto [c, v]: cake) { v -= cost; dp[2] = max(dp[2], make_pair(dp[1].first + v - c * 2, dp[1].second + 1)); dp[1] = max(dp[1], make_pair(dp[1].first + v, dp[1].second + 1)); dp[1] = max(dp[1], make_pair(dp[0].first + v, dp[0].second + 1)); dp[0] = max(dp[0], make_pair(v + c * 2, (int64_t)1)); } return dp[2]; }; int cost = 1 << 29; for (int s = 1 << 29; s; s>>=1) { if (calc(cost - s).second <= m) { cost -= s; } } auto [dp, k] = calc(cost); cout << dp + k * cost << '\n'; /* vector<int64_t> dp(n, -1e18); vector<int64_t> ans(n+1, -1e18); for (int i = 0; i < n; i++) { auto [c, v] = cake[i]; // ans = max(ans, dp[m-1] + v - c * 2); for (int j = 3; j <= n; j++) ans[j] = max(ans[j], dp[j-1] + v - c * 2); for (int j = n-2; j >= 1; j--) { dp[j+1] = max(dp[j+1], dp[j] + v); } dp[1] = max(dp[1], v + c * 2); } cerr << "==========\n"; for (int j = 3; j <= n; j++) cerr << ans[j] - ans[j-1] << '\n'; cout << ans[m] << '\n'; */ }

Compilation message (stderr)

cake3.cpp: In function 'int main()':
cake3.cpp:23:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   23 |     for (auto &[c, v]: cake) cin >> v >> c;
      |                ^
cake3.cpp: In lambda function:
cake3.cpp:30:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   30 |         for (auto [c, v]: cake) {
      |                   ^
cake3.cpp: In function 'int main()':
cake3.cpp:46:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   46 |     auto [dp, k] = calc(cost);
      |          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...