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>
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,ans = LLONG_MAX;
cin >> n >> br;
vector<pair<long long,long long>> haha(n+1,{-1,-1});
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+1] = {h,c};
}
for(long long i = 1; i <= 600; i++) {
idk[i] = min(idk[i],idk[i-1]);
}
sort(haha.begin(),haha.end());
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 = haha[1].first; i < 200; i++) {
dp[1][i][1] = i*br;
}
for(long long i = 2; i <= n; i++) {
for(long long j = haha[i].first; j <= 100; j++) {
for(long long k = i-1; k >= 1; k--) {
for(long long y = 1; y <= i; y++) {
if(i-k >= y) {
dp[i][j][i-k] = min(dp[i][j][i-k],dp[k][j-1][y]+br*(i-k)*j+(i-k-y)*idk[j-1]);
}
else {
dp[i][j][y] = min(dp[i][j][y],dp[k][j-1][y]+br*(i-k)*j);
}
}
}
}
for(long long j = 1; j <= 100; j++) {
for(long long y = 0; y <= n; y++) {
dp[i][j][y] = min(dp[i][j][y],dp[i][j-1][y]);
}
}
}
for(long long i = 0; i <= n; i++) {
ans = min(ans,dp[n][90][i]);
}
for(long long i = 1; i <= n; i++) {
ans-=haha[i].first*br;
}
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... |