Submission #956121

#TimeUsernameProblemLanguageResultExecution timeMemory
956121pccCake 3 (JOI19_cake3)C++17
5 / 100
7 ms4580 KiB
#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; if (r - l < m) return -(int)1e18; 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); FOR(i, 0, n) { if (i == l || i == r - 1) continue; if (p[l].sc <= p[i].sc && p[i].sc <= p[r - 1].sc) 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 mp(a.sc, a.fs) < mp(b.sc, b.fs); }); PSMG::BUILD(); int ans = -1e18; FOR(i, 0, n) FOR(j, i + 1, 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...