Submission #467296

#TimeUsernameProblemLanguageResultExecution timeMemory
467296ivan_tudorHoliday (IOI14_holiday)C++14
24 / 100
5084 ms5752 KiB
#include"holiday.h" #include<bits/stdc++.h> using namespace std; const int N = 100005; int a[N]; multiset<int> big, small; long long sum; int canhold; int L, R; void insert_val(int v){ big.insert(v); sum += v; while((int)big.size() > max(canhold, 0)){ int lval = (*big.begin()); sum -= lval; big.erase(big.begin()); small.insert(lval); } } void erase_val(int v){ if(small.count(v)){ small.erase(small.find(v)); } else if(big.count(v)){ big.erase(big.find(v)); sum -= v; } while((int)big.size() < canhold && small.size() > 0){ int val = (*small.rbegin()); big.insert(val); sum += val; small.erase(small.find(val)); } } void transf(int newL, int newR){ while(L > newL){ canhold -=2; L--; insert_val(a[L]); } while(R < newR){ canhold --; R++; insert_val(a[R]); } while(L < newL){ canhold +=2; erase_val(a[L]); L++; } while(R > newR){ canhold++; erase_val(a[R]); R--; } } long long ans = 0; void solve(int l, int r, int opl, int opr){ int mid = (l + r)/2; long long maxi = -1, mpoz; for(int i = max(opl, mid); i <= opr; i++){ transf(mid, i); if(maxi < sum){ maxi = sum; mpoz = i; } } ans = max(ans, maxi); if(l == r) return; if(l <= mid - 1) solve(l, mid - 1, opl, mpoz); if(mid + 1 <= r) solve(mid + 1, r, mpoz, opr); } long long int findMaxAttraction(int n, int start, int d, int attraction[]) { for(int i = 0; i < n; i++) a[i] = attraction[i]; sum = 0; L = R = start; canhold = d; insert_val(a[start]); solve(0, start, start, n - 1); reverse(a, a+n); start = n - 1 - start; big.clear(); small.clear(); sum = 0; L = R = start; canhold = d; insert_val(a[start]); solve(0, start, 0, n - 1); return ans; }

Compilation message (stderr)

holiday.cpp: In function 'void solve(int, int, int, int)':
holiday.cpp:76:10: warning: 'mpoz' may be used uninitialized in this function [-Wmaybe-uninitialized]
   76 |     solve(mid + 1, r, mpoz, opr);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...