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;
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;
const int MXN = 200005, MXC = 1000000005, LG = 40;
int n, m;
pii p[MXN];
namespace PSMG {
#define mid ((l + r) >> 1)
#define ls(x) nd[x].L
#define rs(x) nd[x].R
struct NODE {
int val, cnt, L, R;
NODE() {}
} nd[MXN * LG];
int nc, rt[MXN];
int new_node(int ref) {
nd[nc] = nd[ref];
return nc++;
}
void pull(int id) {
nd[id].val = nd[ls(id)].val + nd[rs(id)].val;
nd[id].cnt = nd[ls(id)].cnt + nd[rs(id)].cnt;
}
int modify(int pre, int l, int r, int p) {
int id = new_node(pre);
if (l + 1 == r) {
nd[id].val += p;
nd[id].cnt++;
return id;
}
if (p < mid) ls(id) = modify(ls(id), l, mid, p);
else rs(id) = modify(rs(id), mid, r, p);
pull(id);
return id;
}
void BUILD() {
nc = 2;
rt[0] = 1;
FOR(i, 0, n) {
rt[i + 1] = modify(rt[i], 0, MXC, p[i].fs);
}
}
int query(int lid, int rid, int l, int r, int bnd) {
if (l + 1 == r) return l * bnd;
int rval = nd[rs(rid)].val - nd[rs(lid)].val;
int rcnt = nd[rs(rid)].cnt - nd[rs(lid)].cnt;
// debug(l, r, bnd, rval, rcnt);
if (rcnt == bnd) return rval;
if (rcnt > bnd) return query(rs(lid), rs(rid), mid, r, bnd);
return rval + query(ls(lid), ls(rid), l, mid, bnd - rcnt);
}
int QUERY(int l, int r, int bnd) {
return query(rt[l], rt[r], 0, MXC, bnd);
}
#undef mid
#undef ls
#undef rs
}
int calc(int l, int r) {
// int y = PSMG::QUERY(l + 1, r - 1, m - 2);
// int x = p[l].fs + p[l].sc * 2 + p[r - 1].fs - p[r - 1].sc * 2 + y;
// debug(l, r, x, y);
// return x;
int x = p[l].fs + p[l].sc * 2 + p[r - 1].fs - p[r - 1].sc * 2;
vector<int> v;
FOR(i, l + 1, r - 1) v.push_back(p[i].fs);
sort(v.begin(), v.end(), greater<int>());
FOR(i, 0, m - 2) x += v[i];
return x;
}
void miku() {
cin >> n >> m;
assert(n <= 100);
FOR(i, 0, n) cin >> p[i].fs >> p[i].sc;
sort(p, p + n, [](pii a, pii b) -> bool {
return a.sc < b.sc;
});
PSMG::BUILD();
int ans = 0;
FOR(i, 0, n - m) FOR(j, i + m, n + 1) ans = max(ans, calc(i, j));
cout << ans << '\n';
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
miku();
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... |