Submission #146460

#TimeUsernameProblemLanguageResultExecution timeMemory
146460jwvg0425Cake 3 (JOI19_cake3)C++17
0 / 100
3 ms380 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>; void insert(multiset<i64>& s, i64& total, int count, i64 val) { if (s.size() < count) { s.insert(val); total += val; return; } if (*s.begin() > val) return; total -= *s.begin(); s.erase(s.begin()); s.insert(val); total += val; } int main() { int n, m; scanf("%d %d", &n, &m); vector<ii64> cakes(n); map<i64, vector<i64>> cmap; for (int i = 0; i < n; i++) { scanf("%lld %lld", &cakes[i].xx, &cakes[i].yy); cmap[cakes[i].yy].push_back(cakes[i].xx); } vector<pair<i64, vector<i64>>> cvec; for (auto& cm : cmap) { sort(all(cm.yy)); cvec.push_back(cm); } i64 ans = 0; for (int sc = 0; sc < cvec.size(); sc++) { multiset<i64> largest; i64 total = cvec[sc].yy.back(); if (cvec[sc].yy.size() >= m) { i64 s = 0; for (int i = 0; i < m; i++) s += cvec[sc].yy[cvec[sc].yy.size() - 1 - i]; ans = max(ans, s); } for (int bc = sc; bc < cvec.size(); bc++) { for (int i = 0; i < cvec[bc].yy.size() - 1; i++) insert(largest, total, m - 2, cvec[bc].yy[i]); if (sc == bc) continue; i64 now = total + cvec[bc].yy.back(); ans = max(ans, now - 2 * (cvec[bc].xx - cvec[sc].xx)); insert(largest, total, m - 2, cvec[bc].yy.back()); } } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

cake3.cpp: In function 'void insert(std::multiset<long long int>&, i64&, int, i64)':
cake3.cpp:29:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (s.size() < count)
         ~~~~~~~~~^~~~~~~
cake3.cpp: In function 'int main()':
cake3.cpp:70:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int sc = 0; sc < cvec.size(); sc++)
                      ~~~^~~~~~~~~~~~~
cake3.cpp:75:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (cvec[sc].yy.size() >= m)
             ~~~~~~~~~~~~~~~~~~~^~~~
cake3.cpp:84:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int bc = sc; bc < cvec.size(); bc++)
                           ~~~^~~~~~~~~~~~~
cake3.cpp:86:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int i = 0; i < cvec[bc].yy.size() - 1; i++)
                             ~~^~~~~~~~~~~~~~~~~~~~~~~~
cake3.cpp:48: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:56: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...