Submission #146434

#TimeUsernameProblemLanguageResultExecution timeMemory
146434jwvg0425Cake 3 (JOI19_cake3)C++17
0 / 100
3 ms376 KiB
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#define all(x) (x).begin(), (x).end()
#define xx first
#define yy second

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);

    vector<ii64> cakes(n);

    for (int i = 0; i < n; i++)
        scanf("%lld %lld", &cakes[i].xx, &cakes[i].yy);

    sort(all(cakes), [](const ii& l, const ii& r) { return l.yy < r.yy; });

    i64 ans = 0;

    for (int sc = 0; sc < n; sc++)
    {
        multiset<i64> largest;
        i64 sum = 0;

        for (int bc = sc; bc < n; bc++)
        {
            if (largest.size() < m)
            {
                largest.insert(cakes[bc].xx);
                sum += cakes[bc].xx;
            }
            else if(*largest.begin() < cakes[bc].xx)
            {
                sum += cakes[bc].xx;
                sum -= *largest.begin();
                largest.erase(largest.begin());
                largest.insert(cakes[bc].xx);
            }

            if (largest.size() == m && sum - 2 * (cakes[bc].yy - cakes[sc].yy) > ans)
                ans = sum - 2 * (cakes[bc].yy - cakes[sc].yy);
        }
    }

    printf("%lld\n", ans);

    return 0;
}

Compilation message (stderr)

cake3.cpp: In function 'int main()':
cake3.cpp:48:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (largest.size() < m)
                 ~~~~~~~~~~~~~~~^~~
cake3.cpp:61:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (largest.size() == m && sum - 2 * (cakes[bc].yy - cakes[sc].yy) > ans)
                 ~~~~~~~~~~~~~~~^~~~
cake3.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
cake3.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld", &cakes[i].xx, &cakes[i].yy);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...