Submission #838620

#TimeUsernameProblemLanguageResultExecution timeMemory
838620LucaIlieCake 3 (JOI19_cake3)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> #define int long long 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 = 0; 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 ) ) ); } signed 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; }

Compilation message (stderr)

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