Submission #342458

#TimeUsernameProblemLanguageResultExecution timeMemory
342458IZhO_2021_I_want_SilverSchools (IZhO13_school)C++14
100 / 100
280 ms15964 KiB
#include <iostream> #include <algorithm> #include <vector> #include <cmath> #include <set> #include <map> #include <iomanip> #include <cassert> #include <stack> #include <queue> #include <deque> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp>- using namespace std; //using namespace __gnu_pbds; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; // template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // order_of_key (k) : Number of items strictly smaller than k . // find_by_order(k) : K-th element in a set (counting from zero). #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() #define pb push_back #define ppb pop_back #define mkp make_pair #define F first #define S second #define lb lower_bound #define ub upper_bound #define show(a) cerr << #a <<" -> "<< a <<" " #define nl cerr <<"\n" #define int ll const int N = 3e5 + 5; int n, m, s, a[N], b[N], ans, pref[N], suf[N]; vector <pii> vec; multiset <int> st; void solve() { cin >> n >> m >> s; for (int i = 1; i <= n; ++i) { cin >> a[i] >> b[i]; vec.pb({a[i]-b[i], i}); } sort(all(vec)); int sum = 0; if (s > 0) { for (int i = 0; i < s; ++i) { int ind = vec[i].S; st.insert(b[ind]); sum += b[ind]; } pref[s-1] = sum; for (int i = s; i < sz(vec); ++i) { int ind = vec[i].S, mn = *st.begin(); if (b[ind] > mn) { st.erase(st.find(mn)); st.insert(b[ind]); sum -= mn; sum += b[ind]; } pref[i] = sum; } st.clear(); } if (m > 0) { sum = 0; for (int i = sz(vec)-1; i >= sz(vec)-m; --i) { int ind = vec[i].S; st.insert(a[ind]); sum += a[ind]; } suf[sz(vec)-m] = sum; for (int i = sz(vec)-m-1; i >= 0; --i) { int ind = vec[i].S, mn = *st.begin(); if (a[ind] > mn) { st.erase(st.find(mn)); st.insert(a[ind]); sum -= mn; sum += a[ind]; } suf[i] = sum; } st.clear(); } for (int i = 0; i < sz(vec); ++i) { ans = max({ans, pref[i], suf[i]}); if (i + 1 < sz(vec)) { ans = max(ans, pref[i]+suf[i+1]); } if (i - 1 >= 0) { ans = max(ans, pref[i-1]+suf[i]); } } cout << ans; } main () { ios_base::sync_with_stdio(false); cin.tie(NULL); int tests = 1; //cin >> tests; while (tests --) { solve(); } return 0; } /* Just Chalish! */

Compilation message (stderr)

school.cpp:102:8: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  102 |  main () {
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...