Submission #376692

#TimeUsernameProblemLanguageResultExecution timeMemory
3766922qbingxuanCake 3 (JOI19_cake3)C++17
24 / 100
4078 ms3692 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;

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);
    vector<int64_t> dp(m, -1e18);
    for (auto &[c, v]: cake) cin >> v >> c;
    sort(all(cake));
    int64_t ans = -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 = m-2; j >= 1; j--) {
            dp[j+1] = max(dp[j+1], dp[j] + v);
        }
        dp[1] = max(dp[1], v + c * 2);
    }
    cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...