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;
#define int long long
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,k;
cin >> n >> k;
vector<int> cnt(1002);
int ans = 0;
int minh,minc;cin>>minh>>minc;
for(int i=2;i<=n;i++){
int h,c;
cin >> h >> c;
if(h==minh){
ans+=k;
h++;
}
cnt[h]++;
}
auto solve = [&](int x){
for(int i=minh+1;i<=1000;i++){
int temp = max(0ll,cnt[i]-x);
cnt[i]-=temp;
cnt[i+1]+=temp;
ans+=k*temp;
}
};
int actans = INT64_MAX;
for(int i=300;i>=0;i--){
solve(i);
actans = min(actans,ans+max(0ll,minc*(i-1)));
}
cout << actans << '\n';
}
# | 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... |