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;
typedef long long ll;
typedef long double ld;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, m;
cin >> n >> m;
vector <pair <int, int>> a(n);
for (int i = 0; i < n; ++i) cin >> a[i].second >> a[i].first;
sort(a.begin(), a.end());
ll ans = 0;
for (int i = 0; i < n; ++i) {
multiset <int> cur;
for (int j = i; j < n; ++j) {
cur.insert(a[j].second);
if (cur.size() >= m) {
ll res = 0;
auto uk = --cur.end();
for (int k = 0; k < m; ++k) {
res += *uk;
if (k + 1 < m) --uk;
}
ans = max(ans, res - 2LL * a[j].first + 2LL * a[i].first);
}
}
}
cout << ans << '\n';
}
Compilation message (stderr)
cake3.cpp: In function 'int main()':
cake3.cpp:24:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (cur.size() >= m) {
~~~~~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |