This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |