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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define bpc __builtin_popcount
#define mp make_pair
#define ull unsigned long long
#define ld double
#define ll long long
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
typedef tree<long long, null_type, less_equal<long long>,
rb_tree_tag, tree_order_statistics_node_update> Tree;
const ll INF = 9223372036854775807LL;
const ll inf = 2147483647;
const ll MOD = 1e9 + 7;
const ld PI = acos(-1);
const ll NROOT = 320;
//void FileIO(string in, string out) {
//#ifndef LOCAL
// freopen(in, "r", stdin);
// freopen(out, "w", stdout);
//#endif
//}
ll binpow(ll a, ll b) {
ll res = 1;
for (; b; b /= 2, a *= a, a %= MOD)
if (b & 1) res *= a, res %= MOD;
return res;
}
bool dataOverflow(ll a, ll b) {return (log10(a) + log10(b) >= 18);}
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
ll invmod(ll a) {return binpow(a, MOD - 2);}
ll ceil(ll a, ll b) {return (a + b - 1) / b;}
void print(priority_queue<ll, vector<ll>, greater<ll>> q) {
int cnt = 0;
while (!q.empty()) {
if (cnt > 0)
cerr << " ";
cerr << q.top();
q.pop();
cnt ++;
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
vector<pair<ll, ll>> v(n + 1);
for (int i = 1; i <= n; i ++)
cin >> v[i].S >> v[i].F;
sort(v.begin() + 1, v.end());
for (auto &x : v) {
swap(x.F, x.S);
}
ll ans = 0;
for (int i = 1; i <= n; i ++) {
ll act = 0;
priority_queue<ll, vector<ll>, greater<ll>> q;
for (int j = i + 1; j <= n; j ++) {
if ((int)q.size() == (m - 2)) {
ll tmp = act + v[i].F + v[j].F;
tmp -= 2LL * (v[j].S - v[i].S);
ans = max(ans, tmp);
// cerr << i << " " << j << ": {";
// print(q);
// cerr << "} => " << tmp << '\n';
q.push(v[j].F);
act += v[j].F;
act -= q.top();
q.pop();
} else {
q.push(v[j].F);
act += v[j].F;
}
}
}
cout << ans << "\n";
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... |