Submission #1043871

#TimeUsernameProblemLanguageResultExecution timeMemory
1043871vjudge1Schools (IZhO13_school)C++17
100 / 100
66 ms11476 KiB
#include <bits/stdc++.h> #define file "main" #define maxn (int) 3e5 + 5 #define pii pair<int, int> #define ll long long #define gb(i, j) ((i >> j) & 1) #define _left id * 2, l, mid #define _right id * 2 + 1, mid + 1, r #define f first #define s second using namespace std; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll GetRandom(ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rng); } void iof() { if(fopen(file".inp", "r")) { freopen(file".inp", "r", stdin); // freopen(file".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); } int n, m, t; pii a[maxn]; ll L[maxn], R[maxn]; void solve() { cin >> n >> m >> t; for(int i = 1; i <= n; i ++) cin >> a[i].f >> a[i].s; sort(a + 1, a + n + 1, [](pii& x, pii& y) { return x.f - y.f > x.s - y.s; }); priority_queue<int> q; ll sum = 0; for(int i = 1; i <= n; i ++) { q.push( -a[i].f ), sum += a[i].f; if(q.size() < m) L[i] = -1e18; else if(q.size() == m) L[i] = sum; else { ll val = -q.top(); q.pop(); sum -= val, L[i] = sum; } } while(q.size()) q.pop(); sum = 0; for(int i = n; i >= 1; i --) { q.push( -a[i].s ), sum += a[i].s; if(q.size() < t) R[i] = -1e18; else if(q.size() == t) R[i] = sum; else { int val = -q.top(); q.pop(); sum -= val, R[i] = sum; } } ll ans = 0; for(int i = 1; i <= n; i ++) { ans = max(ans, L[i] + R[i + 1]); } cout << ans; } int main() { iof(); int nTest = 1; // cin >> nTest; while(nTest --) { solve(); } return 0; }

Compilation message (stderr)

school.cpp: In function 'void solve()':
school.cpp:45:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |         if(q.size() < m) L[i] = -1e18;
      |            ~~~~~~~~~^~~
school.cpp:46:26: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   46 |         else if(q.size() == m) L[i] = sum;
      |                 ~~~~~~~~~^~~~
school.cpp:57:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |         if(q.size() < t) R[i] = -1e18;
      |            ~~~~~~~~~^~~
school.cpp:58:26: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   58 |         else if(q.size() == t) R[i] = sum;
      |                 ~~~~~~~~~^~~~
school.cpp: In function 'void iof()':
school.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen(file".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...