제출 #533201

#제출 시각아이디문제언어결과실행 시간메모리
533201Soumya1Cake 3 (JOI19_cake3)C++17
0 / 100
6 ms332 KiB
#include <bits/stdc++.h>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
void testCase() {
  int n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> a(n);
  for (auto &[x, y] : a) cin >> y >> x;
  sort(a.begin(), a.end());
  long long mx = 0;
  for (int i = m - 1; i < n; i++) {
    for (int j = 0; j <= i - m + 1; j++) {
      vector<long long> v;
      for (int k = j; k <= i; k++) v.push_back(a[k].second);
      sort(v.rbegin(), v.rend());
      long long ans = 0;
      for (int k = 0; k < m; k++) ans += v[k];
      ans -= 2 * (a[i].first - a[j].first);
      mx = max(mx, ans);
    }
  }
  cout << mx << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  testCase();
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...