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(i, a, b) for( int i = a; i <= b; i++ )
#define fid(i, a, b) for( int i = a; i >= b; i-- )
#define getbit(x, i) ((x>>i)&1)
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define st first
#define nd second
#define mp make_pair
#define HTManh ""
#define maxn 100009
#define endl '\n'
using namespace std;
int n;
ll k;
pll a[309];
ll dp[309];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL); cout.tie(NULL);
if (fopen(HTManh".inp", "r"))
{
freopen(HTManh".inp", "r", stdin);
freopen(HTManh".out", "w", stdout);
}
cin >> n >> k;
fi(i,1,n) cin >> a[i].st >> a[i].nd;
sort(a+1,a+n+1);
int vt = 0;
fi(i,1,n+1) if (a[i].st != a[1].st || i == n+1)
{
vt = i-1;
break;
}
ll res = 0;
fi(i,2,vt)
{
a[i].st++;
res += k;
}
ll mn, dem;
mn = a[1].nd, dem = 1;
int dau = 2, cuoi = 2;
while(dau <= n)
{
while(a[dau].st == a[cuoi].st && cuoi <= n) cuoi++;
cuoi--;
fi(i,dau,cuoi)
{
if (dem > 0) dem--;
else res += mn;
}
fi(i,dau,cuoi) mn = min(mn, a[i].nd);
dem += cuoi-dau+1;
dau = cuoi + 1;
cuoi = dau;
}
cout << res << endl;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | freopen(HTManh".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | freopen(HTManh".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |