Submission #756504

#TimeUsernameProblemLanguageResultExecution timeMemory
756504OlympiaSchools (IZhO13_school)C++17
95 / 100
2076 ms25148 KiB
#include <vector> #include <iostream> #include <cassert> #include <random> #include <cmath> #include <map> #include <algorithm> #include <bitset> #include <random> #include <queue> #include <set> #include <stack> #define ll int64_t using namespace std; bool comp (pair<int64_t, int64_t> p1, pair<int64_t, int64_t> p2) { return (p1.first - p1.second < p2.first - p2.second); } void print (vector<ll> v) { for (ll x: v) { cout << x << ' '; } cout << endl; } vector<ll> get_max (vector<ll> v, int k) { multiset<ll> best; vector<ll> ans; ans.push_back(-1e17); ll sum = 0; for (int i = 0; i < v.size(); i++) { if (i <= k - 1) { best.insert(v[i]); sum += v[i]; } else { if (v[i] >= *(best.begin())) { sum -= *(best.begin()); best.erase(best.find(*(best.begin()))); sum += v[i]; best.insert(v[i]); } } ans.push_back(((i >= k - 1) ? sum : -1e17)); /* for (ll x: best) { cout << x << " "; } cout << endl; */ } return ans; } int main () { ios_base::sync_with_stdio(false); cin.tie(NULL); int N, M, S; cin >> N >> M >> S; vector<pair<ll,ll>> vec(N); vec.resize(N); for (int i = 0; i < N; i++) { cin >> vec[i].first >> vec[i].second; } sort(vec.begin(), vec.end(), comp); vector<ll> a, b; for (int i = 0; i < N; i++) { a.push_back(vec[i].first), b.push_back(vec[i].second); } reverse(a.begin(), a.end()); //print(a); auto res1 = get_max(a, M); //print(res1); auto res2 = get_max(b, S); reverse(res2.begin(), res2.end()); //print(res2); int64_t ans = 0; for (int i = 0; i <= N; i++) { ans = max(ans, res1[i] + res2[i]); //cout << res1[i] << " " << res2[i] << endl; } cout << ans; }

Compilation message (stderr)

school.cpp: In function 'std::vector<long int> get_max(std::vector<long int>, int)':
school.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for (int i = 0; i < v.size(); i++) {
      |                  ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...