Submission #856363

#TimeUsernameProblemLanguageResultExecution timeMemory
856363yuriconHoliday (IOI14_holiday)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define task "STOUR" #define ll long long #define pb push_back const int N = 1e5 + 6; int n, s, d, a[N]; void sub2() { priority_queue <int, vector <int>, greater <int> > pq; ll sum = 0, ans = 0; int cnt = 0; for(int i = s; i < n; ++i) { sum += a[i]; cnt++; pq.push(a[i]); while(!pq.empty() && cnt + s - i > d) { sum -= pq.top(); pq.pop(); cnt--; } ans = max(ans, sum); } sum = cnt = 0; for(int i = s; i >= 0; --i) { sum += a[i]; cnt++; pq.push(a[i]); while(!pq.empty() && cnt + i - s > d) { sum -= pq.top(); pq.pop(); cnt--; } ans = max(ans, sum); } cout << ans; } void sub3() { ll ans = 0; for(int i = 0; i < n; ++i) { int c = d - abs(s - i); if(i <= s) { priority_queue <int, vector <int>, greater <int> > pq; ll sum = 0; int cnt = 0; for(int j = i; j < n; ++j) { sum += a[j]; cnt++; pq.push(a[j]); while(!pq.empty() && cnt + j - i > c) { sum -= pq.top(); pq.pop(); cnt--; } ans = max(ans, sum); } } if(i >= s) { priority_queue <int, vector <int>, greater <int> > pq; ll sum = 0; int cnt = 0; for(int j = i; j >= 0; --j) { sum += a[j]; cnt++; pq.push(a[j]); while(!pq.empty() && cnt + (i - j) > c) { sum -= pq.top(); pq.pop(); cnt--; } ans = max(ans, sum); } } } cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); freopen(task".inp","r",stdin); freopen(task".out","w",stdout); cin >> n >> s >> d; for(int i = 0; i < n; ++i) { cin >> a[i]; } if(n <= 3000) { sub3(); return 0; } sub2(); }

Compilation message (stderr)

holiday.cpp: In function 'int main()':
holiday.cpp:94:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
holiday.cpp:95:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccsWGp5e.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc3Yq2Ch.o:holiday.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccsWGp5e.o: in function `main':
grader.cpp:(.text.startup+0xaf): undefined reference to `findMaxAttraction(int, int, int, int*)'
collect2: error: ld returned 1 exit status