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;
int n;
pair<long long,long long> a[305];
int b[305];
long long k;
bool cmp(pair<long long,long long> a,pair<long long,long long>b)
{
if(a.first>b.first) return false;
if(a.first<b.first) return true;
return a.second>b.second;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
for(int i=0;i<n;i++)
{
cin >> a[i].first >> a[i].second;
b[i]=1;
}
sort(a,a+n);
long long res=0;
for(int i=1;i<n;i++)
{
if(a[i].first==a[0].first)
{
res+=k;
a[i].first++;
}
else break;
}
sort(a+1,a+n,cmp);
int mn=0;
for(int i=1;i<n;i++)
{
if(b[mn]==0)
{
res+=a[mn].second;
}
else b[mn]--;
if(a[i].first!=a[i+1].first)
{
if(a[mn].second>a[i].second) mn=i;
}
}
cout << res;
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... |