Submission #1033377

#TimeUsernameProblemLanguageResultExecution timeMemory
1033377onbertHoliday (IOI14_holiday)C++17
100 / 100
71 ms8856 KiB
#include "holiday.h" #include <bits/stdc++.h> using namespace std; #define int long long const int maxn = 1e5 + 5; int n, a[maxn]; int solve(int S, int d) { int ans = 0, curans = 0; priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq; for (int i=S;i<=n;i++) { pq.push({a[i], -i}), curans += a[i]; while (pq.size() > 0 && i-S + pq.size() > d) { curans -= pq.top().first; pq.pop(); } ans = max(curans, ans); } while (pq.size() > 0) pq.pop(); curans = 0; set<int> s; for (int i=S;i<=n;i++) { pq.push({a[i], -i}), s.insert(i), curans += a[i]; while (pq.size() > 0 && i-S + pq.size() > d) { curans -= pq.top().first; s.erase(-pq.top().second); pq.pop(); } if (curans==ans) break; } for (int i=S-1, D = d-1; i>=1 && D>=1; i--, D--) { pq.push({a[i], -i}), s.insert(i), curans += a[i]; while (pq.size() > 0 && *s.rbegin()-i + pq.size() > D) { curans -= pq.top().first; s.erase(-pq.top().second); pq.pop(); } ans = max(curans, ans); } return ans; } int findMaxAttraction(int32_t N, int32_t S, int32_t D, int32_t A[]) { n = N, S++; for (int i=1;i<=n;i++) a[i] = A[i-1]; int ans1 = solve(S, D); reverse(a+1, a+n+1); S = n+1-S; int ans2 = solve(S, D); return max(ans1, ans2); }

Compilation message (stderr)

holiday.cpp: In function 'long long int solve(long long int, long long int)':
holiday.cpp:13:49: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
   13 |         while (pq.size() > 0 && i-S + pq.size() > d) {
      |                                 ~~~~~~~~~~~~~~~~^~~
holiday.cpp:24:49: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
   24 |         while (pq.size() > 0 && i-S + pq.size() > d) {
      |                                 ~~~~~~~~~~~~~~~~^~~
holiday.cpp:34:59: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
   34 |         while (pq.size() > 0 && *s.rbegin()-i + pq.size() > D) {
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...