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 INF 1e18
#define fi first
#define se second
#define FOR(i, k, n) for(ll i = k; i <= n; i++)
#define FOR1(i, k, n) for(ll i = k; i >= n; i--)
#define pb push_back
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define ll long long
#define vll vector<ll>
#define pll pair<ll, ll>
#define re return 0
#define mii map<int, int>
#define input "BESIEGE.inp"
#define output "BESIEGE.out"
#define rf freopen(input, "r", stdin); freopen(output, "w", stdout)
#define int ll
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
const int base = 998244353;
void add(int &a, int b)
{
a += b;
if(a >= mod) a -= mod;
if(a < 0) a += mod;
}
pii a[maxn];
bool vis[maxn];
int b[maxn];
bool cmp(pii x, pii y)
{
return x.fi > y.fi;
}
signed main()
{
fastio;
int n, k;
cin >> n >> k;
FOR(i, 1, n)
cin >> a[i].fi >> a[i].se;
if(n == 1)
{
cout << 0;
re;
}
ll ans = 0;
sort(a + 1, a + 1 + n);
FOR(i, 2, n)
if(a[i].fi == a[1].fi)
ans += k, a[i].fi++;
sort(a + 2, a + 2 + n, cmp);
FOR(i, 1, n - 1)
{
bool ok = 1;
FOR(j, 2, i + 1)
b[j - 1] = a[j].fi;
FOR(j, i + 2, n)
{
int t = j - 1;
t %= i;
if(t == 0)
t = i;
if(a[j].fi >= b[t])
{
ok = 0;
break;
}
b[t] = a[j].fi;
}
if(ok)
{
cout << ans + a[1].se * (i - 1);
re;
}
}
re;
}
# | 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... |