제출 #362670

#제출 시각아이디문제언어결과실행 시간메모리
362670hoaphat1Cake 3 (JOI19_cake3)C++17
24 / 100
4099 ms2320 KiB
#include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); 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()); /* k1 k2 ... km -> v - 2 * (c km - c k1) i >= i-1 */ auto work = [&]() { long long ans = -1e18; for (int i = 0; i < n; i++) { priority_queue<int, vector<int> ,greater<int>> pq; long long now = 0; for (int j = i + 1; j < n; j++) { if (pq.size() == m - 2) { ans = max(ans, now + a[j].second + a[i].second - 2 * (a[j].first - a[i].first)); } now += a[j].second; pq.push(a[j].second); if (pq.size() > m - 2) { now -= pq.top(); pq.pop(); } } } cout << ans << endl; }; long long ans = -1e18; priority_queue<int, vector<int>, greater<int>> pq; function<void(int, int, int, int)> solve = [&](int l, int r, int L, int R) { if (l > r) return ; int mid = l + r >> 1; int pos = -1; long long now = 0; while (!pq.empty()) pq.pop(); for (int i = mid - 1; i > R; i--) { now += a[i].second; pq.push(a[i].second); if ((int)pq.size() > m - 2) now -= pq.top(), pq.pop(); } long long val = 0; for (int i = min(mid-1, R); i >= L; i--) { if ((int) pq.size() == m - 2) { if (val < now + a[i].second + 2 * a[i].first) { val = now + a[i].second + 2 * a[i].first; pos = i; } } pq.push(a[i].second); now += a[i].second; if ((int)pq.size() > m - 2) { now -= pq.top(); pq.pop(); } } ans = max(ans, val + a[mid].second - 2 * a[mid].first); solve(l, mid - 1, L, pos); solve(mid + 1, r, pos, R); }; solve(m-1, n-1, 0, n-1); ///work(); cout << ans; }

컴파일 시 표준 에러 (stderr) 메시지

cake3.cpp: In lambda function:
cake3.cpp:23:20: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |      if (pq.size() == m - 2) {
      |          ~~~~~~~~~~^~~~~~~~
cake3.cpp:28:19: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |     if (pq.size() > m - 2) {
      |         ~~~~~~~~~~^~~~~~~
cake3.cpp: In lambda function:
cake3.cpp:40:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |    int mid = l + r >> 1;
      |              ~~^~~
cake3.cpp: In function 'int main()':
cake3.cpp:17:8: warning: variable 'work' set but not used [-Wunused-but-set-variable]
   17 |   auto work = [&]() {
      |        ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...