이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 ++;
}
}
bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
if (a.S == b.S)
return a.F < b.F;
return a.S < b.S;
}
void comp(bool stat) {
if (!stat) {
while (true) {
cerr << "Another Loop\n";
}
exit(0);
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m; m -= 2;
vector<pair<ll, ll>> v(n + 1);
for (int i = 1; i <= n; i ++)
cin >> v[i].F >> v[i].S;
sort(v.begin(), v.end(), cmp);
ll ans = -1e18;
for (int i = 1; i <= n; i ++) {
ll act = v[i].F;
priority_queue<ll, vector<ll>, greater<ll>> q;
for (int j = i + 1; j <= n; j ++) {
if ((int)q.size() == m) {
ll tmp = act + v[j].F;
tmp -= (v[j].S + v[j].S - v[i].S - v[i].S);
ans = max(ans, tmp);
q.push(v[j].F);
act += v[j].F;
if (q.empty()) {
while(true) {
cerr << "Another Loop\n";
}
}
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... |