This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Knapsack DP is harder than FFT.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii; typedef pair<ll,ll> pll;
#define ff first
#define ss second
#define pb emplace_back
#define FOR(i,n) for(int i = 0; i < (n); ++i)
#define FOO(i,a,b) for(int i = (a); i <= (b); ++i)
#define AI(x) begin(x),end(x)
template<class I> bool chmax(I &a, I b){ return a < b ? (a = b, true) : false;}
template<class I> bool chmin(I &a, I b){ return a > b ? (a = b, true) : false;}
#ifdef OWO
#define debug(args...) LKJ("[ " + string(#args) + " ]", args)
void LKJ(){ cerr<<endl;}
template<class I, class...T> void LKJ(I&&x, T&&...t){ cerr<<x<<", ", LKJ(t...);}
template<class I> void DE(I a, I b){ while(a < b) cerr<<*a<<" \n"[next(a) == b], ++a;}
#else
#define debug(...) 0
#define DE(...) 0
#endif
const int N = 2e3 + 225;
int n, m;
struct cake{
ll v, c;
cake(ll v = 0, ll c = 0):
v(v), c(c){}
bool operator<(const cake &a){
return c < a.c;
}
} C[N];
ll dp[N][N];
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
FOO(i,1,n){
ll v, c;
cin >> v >> c;
C[i] = cake(v, c);
}
sort(C + 1, C + n + 1);
FOR(i,n+1) FOR(j,n+1) dp[i][j] = -1e18;
dp[0][0] = 0;
FOO(i,1,n){
dp[i][1] = C[i].v;
FOO(j,2,min(i,m)){
chmax(dp[i][j], dp[i-1][j-1] + C[i].v - 2 * (C[i].c - C[i-1].c));
chmax(dp[i][j], dp[i-1][j] - 2 * (C[i].c - C[i-1].c));
}
debug(i);
DE(dp[i] + 1, dp[i] + min(i, m) + 1);
}
ll ans = -1e18;
FOO(i,m,n) chmax(ans, dp[i][m]);
cout << ans;
return 0;
}
Compilation message (stderr)
cake3.cpp: In function 'int32_t main()':
cake3.cpp:20:20: warning: statement has no effect [-Wunused-value]
20 | #define debug(...) 0
| ^
cake3.cpp:53:3: note: in expansion of macro 'debug'
53 | debug(i);
| ^~~~~
cake3.cpp:21:17: warning: statement has no effect [-Wunused-value]
21 | #define DE(...) 0
| ^
cake3.cpp:54:3: note: in expansion of macro 'DE'
54 | DE(dp[i] + 1, dp[i] + min(i, m) + 1);
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |