Submission #450201

#TimeUsernameProblemLanguageResultExecution timeMemory
450201blueCake 3 (JOI19_cake3)C++17
Compilation error
0 ms0 KiB
#include <iostream> #include <vector> #include <algorithm> #include <set> using namespace std; struct piece { long long V; long long C; }; bool operator < (piece A, piece B) { return A.C < B.C; } int main() { int N, M; vector<piece> P; cin >> N >> M; P = vector<piece>(N); for(int i = 0; i < N; i++) cin >> P[i].V >> P[i].C; sort(P.begin(), P.end()); long long res = 0; for(int L = 0; L <= N-M; L++) { long long sm = 0; multiset<long long> vals; for(int i = L+1; i <= L+M-2; i++) { vals.insert(P[i].V); sm += P[i].V; } assert(vals.size() == M-2); res = max(res, P[L].V + sm + P[L+M-1].V - 2*(P[L+M-1].C - P[L].C)); for(int i = L+M-1; i+1 < N; i++) { vals.insert(P[i].V); sm += P[i].V; if(vals.size() > M-2) { sm -= *vals.begin(); vals.erase(vals.begin()); } assert(vals.size() == M-2); res = max(res, P[L].V + sm + P[i+1].V - 2*(P[i+1].C - P[L].C)); } } cout << res << '\n'; }

Compilation message (stderr)

cake3.cpp: In function 'int main()':
cake3.cpp:39:28: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   39 |         assert(vals.size() == M-2);
      |                ~~~~~~~~~~~~^~~~~~
cake3.cpp:39:9: error: 'assert' was not declared in this scope
   39 |         assert(vals.size() == M-2);
      |         ^~~~~~
cake3.cpp:5:1: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
    4 | #include <set>
  +++ |+#include <cassert>
    5 | using namespace std;
cake3.cpp:47:28: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |             if(vals.size() > M-2)
      |                ~~~~~~~~~~~~^~~~~
cake3.cpp:52:32: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   52 |             assert(vals.size() == M-2);
      |                    ~~~~~~~~~~~~^~~~~~