이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=310;
const ll inf=1e18;
int n, z, cnt[N];
ll f[N][N][N], c[N];
pair<int, int> a[N];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> z;
for (int i=1; i<=n; ++i){
cin >> a[i].first >> a[i].second;
++a[i].first;
++cnt[a[i].first];
}
for (int i=0; i<N; ++i) c[i]=inf;
for (int i=1; i<=n; ++i) c[a[i].first+1]=min(c[a[i].first+1], (ll)a[i].second);
for (int i=1; i<N; ++i) c[i]=min(c[i], c[i-1]);
for (int i=0; i<N; ++i) for (int j=0; j<N; ++j) for (int k=0; k<N; ++k) f[i][j][k]=inf;
f[0][1][0]=0;
for (int i=0; i<N-1; ++i) for (int j=0; j<=n; ++j) for (int k=0; k<=n; ++k) if (f[i][j][k]!=inf){
for (int d=-cnt[i+1]; d<=k; ++d){
int x=cnt[i+1]+d;
if (c[i+1]==inf && x-j>0) continue;
f[i+1][max(j, x)][k-d]=min(f[i+1][max(j, x)][k-d], f[i][j][k]+1ll*max(0, x-j)*c[i+1]+1ll*(k-d)*z);
}
}
ll ans=inf;
for (int i=0; i<=n; ++i) ans=min(ans, f[N-1][i][0]);
cout << ans << '\n';
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... |