제출 #838622

#제출 시각아이디문제언어결과실행 시간메모리
838622LucaIlieCake 3 (JOI19_cake3)C++17
24 / 100
4014 ms8304 KiB
#include <bits/stdc++.h> using namespace std; struct ab { int a, b; }; int m; const int MAX_N = 2e5; const long long INF = 1e18; ab v[MAX_N]; multiset<int> s; long long solve( int ll, int lr, int rl, int rr ) { if ( ll > lr ) return -INF; int l = (ll + lr) / 2; long long sumA = 0, answer = -INF; int bestR = rr; s.clear(); for ( int r = l; r <= rr; r++ ) { s.insert( v[r].a ); sumA += v[r].a; if ( s.size() > m ) { sumA -= *s.begin(); s.erase( s.begin() ); } if ( s.size() >= m && r >= rl ) { if ( sumA - 2 * (v[r].b - v[l].b) > answer ) { answer = sumA - 2 * (v[r].b - v[l].b); bestR = r; } } } return max( answer, max( solve( ll, l - 1, rl, bestR ), solve( l + 1, lr, bestR, rr ) ) ); } int main() { int n; cin >> n >> m; for ( int i = 1; i <= n; i++ ) cin >> v[i].a >> v[i].b; sort( v + 1, v + 1 + n, []( ab x, ab y ) { return x.b < y.b; } ); cout << solve( 1, n, 1, n ); return 0; }

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

cake3.cpp: In function 'long long int solve(int, int, int, int)':
cake3.cpp:27:23: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |         if ( s.size() > m ) {
      |              ~~~~~~~~~^~~
cake3.cpp:32:23: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |         if ( s.size() >= m && r >= rl ) {
      |              ~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...