이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define MP make_pair
#define PB push_back
int N,M;
pair<LL,LL> CV[200000];
LL dp[2000][2000];
LL solve(int now, int nokori){ //now wo eranda
if(nokori == 0) return 0;
if(dp[now][nokori] != LLONG_MAX) return dp[now][nokori];
LL ans = LLONG_MIN;
for(int i=now+1; i<=N-nokori; i++){
ans = max(ans, CV[i].second-(CV[i].first-CV[now].first)*2+solve(i, nokori-1));
}
return dp[now][nokori] = ans;
}
LL answer(){
LL ans = LLONG_MIN;
for(int i=0; i<=N-M; i++){
ans = max(ans, CV[i].second+solve(i, M-1));
}
return ans;
}
int main(){
cin >> N >> M;
if(N > 2000) return -1;
for(int i=0; i<N; i++){
cin >> CV[i].second >> CV[i].first;
for(int j=0; j<N; j++) dp[i][j] = LLONG_MAX;
}
sort(CV, CV+N);
cout << answer() << endl;
for(int i=0; i<N; i++){
if(i <= N-M) cout << CV[i].second+solve(i, M-1) << "\t";
else cout << "\t";
for(int j=M; j>=0; j--){
if(i >= N-j){
cout << "\t";
continue;
}
cout << solve(i, j) << "\t";
}
cout << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |