#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n,k;
cin>>n>>k;
ll h[n+5],c[n+5];
for(ll i=1;i<=n;i++){
cin>>h[i]>>c[i];
}
ll ans=(ll)1e18;
ll a[n+5];
for(ll i=1;i<=n;i++){
ll cost=0;
for(ll j=1;j<=n;j++) a[j]=h[j];
for(ll j=1;j<=n;j++){
if(i!=j){
cost+=(max(a[i]+1,a[j])-a[j])*k;
a[j]=max(a[i]+1,a[j]);
}
}
ll ord[n+5];
iota(ord+1,ord+n+1,1);
sort(ord+1,ord+n+1,[&](ll i,ll j){
return a[i]<a[j];
});
ll cnt[n+5];
fill(cnt,cnt+n+1,1);
for(ll j=2;j<=n;j++){
bool flag=false;
for(ll l=1;l<j;l++){
if(a[ord[l]]==a[ord[j]]) break;
if(cnt[ord[l]]==1){
cnt[ord[l]]=0;
flag=true;
break;
}
}
if(!flag){
ll C=(ll)1e18;
for(ll l=1;l<j;l++){
if(a[ord[l]]==a[ord[j]]) break;
C=min(C,c[ord[l]]);
}
cost+=C;
}
}
ans=min(ans,cost);
}
cout<<ans;
}
# | 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... |