Submission #450213

#TimeUsernameProblemLanguageResultExecution timeMemory
450213blueCake 3 (JOI19_cake3)C++17
0 / 100
21 ms296 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cassert>
using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;

    long long V[N], C[N];
    for(int i = 0; i < N; i++) cin >> V[i] >> C[i];

    long long res = 0;

    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < N; j++)
        {
            if(i == j) continue;
            if(C[i] > C[j]) continue;

            multiset<long long> H;
            for(int k = 0; k < N; k++)
            {
                if(k == i || k == j) continue;
                if(C[k] < C[i] || C[j] < C[k]) continue;
                H.insert(V[k]);
            }
            while(H.size() > M-2) H.erase(H.find(*H.begin()));

            // cerr << i << ' ' << j << ": ";
            // for(long long h:H) cerr << h << ' ';
            // cerr << '\n';

            if(H.size() < M-2) continue;

            long long curr = -2*(C[j] - C[i]) + V[i] + V[j];
            for(long long q: H) curr += q;

            res = max(res, curr);
        }
    }

    cout << res << '\n';
}

Compilation message (stderr)

cake3.cpp: In function 'int main()':
cake3.cpp:32:28: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |             while(H.size() > M-2) H.erase(H.find(*H.begin()));
      |                   ~~~~~~~~~^~~~~
cake3.cpp:38:25: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   38 |             if(H.size() < M-2) continue;
      |                ~~~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...