This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author : Lăng Trọng Đạt
* created: 2024-08-25
**/
#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define int long long
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
using pii = pair<int, int>;
using vi = vector<int>;
#define FOR(i, a, b) for (int i = a; (i) <= (b); i++)
void mx(int& a, int b) { if (b > a) a = b; }
void mi(int& a, int b) { if (b < a) a = b; }
#define si(x) (int)(x.size())
const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
int dp[N];
int g[N];
int n, m, k, a, b;
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("hi.inp", "r")) {
freopen("hi.inp", "r", stdin);
// freopen("hi.out", "w", stdout);
}
cin >> n >> m;
vector<pii> p(n);
for (auto&[c, v] : p) cin >> v >> c;
sort(all(p));
memset(dp, -0x3f, sizeof(dp));
for (int i = n - 1; i >= 0; i--) {
mx(dp[m], dp[m - 1] + p[i].se + 2*p[i].f);
for (int j = m - 1; j > 1; j--) {
mx(dp[j], dp[j - 1] + p[i].se);
}
mx(dp[1], p[i].se - 2*p[i].f);
}
db(dp[m - 1])
cout << dp[m];
}
Compilation message (stderr)
cake3.cpp: In function 'int32_t main()':
cake3.cpp:40:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
40 | for (auto&[c, v] : p) cin >> v >> c;
| ^
cake3.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | freopen("hi.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |