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>
#define fi first
#define se second
#define ll long long
#define pb push_back
using namespace std;
ll n,k,h[100005],c[100005],ans,sl;
pair<int,int> p[100005];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen(".INP","r",stdin);
// freopen(".OUT","w",stdout);
cin>>n>>k;
for(int i=1;i<=n;i++)
{
cin>>h[i]>>c[i];
p[i]={h[i],c[i]};
}
sort(p+1,p+1+n);
for(int i=2;i<=n;i++)
{
if(p[1].fi==p[i].fi)
{
p[i].fi++;
ans+=k;
}
else break;
}
int mn=p[1].se;
sl=1;
for(int i=2;i<=n;i++)
{
int j=i;
while(j<=n&&p[i].fi==p[j].fi)
{
j++;
}
for(int k=i;k<j;k++)
{
if(sl>0) sl--;
else
ans+=mn;
}
for(int k=i;k<j;k++)
{
mn=min(mn,p[k].se);
sl++;
}
i=j-1;
}
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... |