이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
long long dp[301][601][301];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n,br,h,c;
cin >> n >> br;
vector<pair<long long,long long>> haha(n);
vector<long long> idk(601,INT_MAX);
for(long long i = 0; i < n; i++) {
cin >> h >> c;
idk[h] = min(idk[h],c);
haha[i] = {h,c};
}
for(long long i = 1; i <= 600; i++) {
idk[i] = min(idk[i],idk[i-1]);
}
sort(haha.begin(),haha.end());
haha.push_back({INT_MAX,INT_MAX});
reverse(haha.begin(),haha.end());
for(long long i = n-1; i >= 1; i--) {
haha[i] = {haha[i].first,min(haha[i].second,haha[i+1].second)};
}
for(long long i = 0; i < 301; i++) {
for(long long j = 0; j < 601; j++) {
for(long long k = 0; k < 301; k++) {
dp[i][j][k] = LLONG_MAX/10;
}
}
}
for(long long i = 0; i < 200; i++) {
dp[0][i][0] = 0;
}
for(long long i = 1; i <= n; i++) {
for(long long j = 10; j >= 0; j--) {
for(long long k = i-1; k >= 0; k--) {
dp[i][j][i-k] = dp[i][j+1][i-k];
if(haha[k+1].first > j) {
continue;
}
for(long long y = 0; y <= i; y++) {
if(idk[j] != INT_MAX) {
dp[i][j][i-k] = min(dp[i][j][i-k],dp[k][j+1][y]+br*j*(i-k)+idk[j]*max(0LL,y-(i-k)));
}
}
}
}
}
long long ans = LLONG_MAX;
for(long long i = 0; i <= 100; i++) {
ans = min(ans,dp[n][i][1]);
}
for(long long i = 1; i <= n; i++) {
ans-=br*haha[i].first;
}
cout << ans;
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |