Submission #790699

#TimeUsernameProblemLanguageResultExecution timeMemory
790699petezaMeetings (IOI18_meetings)C++14
19 / 100
628 ms2900 KiB
#include "meetings.h" #include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; struct stk { long long sum = 0; stack<pii> st; stk():sum(0){while(!st.empty())st.pop();} void add(int x) { int cur = 1; while(!st.empty() && st.top().first <= x) { cur += st.top().second; sum -= 1ll*st.top().first*st.top().second; st.pop(); } st.emplace(x, cur); sum += 1ll*x*cur; } } ls, rs; long long l[5005], r[5005]; std::vector<long long> minimum_costs(std::vector<int> H, std::vector<int> L, std::vector<int> R) { int Q = L.size(); std::vector<long long> C(Q); for (int j = 0; j < Q; ++j) { C[j] = __LONG_LONG_MAX__; ls = stk(); rs = stk(); for(int i=L[j];i<=R[j];i++) { ls.add(H[i]); l[i] = ls.sum; } for(int i=R[j];i>=L[j];i--) { rs.add(H[i]); r[i] = rs.sum; } for(int i=L[j];i<=R[j];i++) { C[j] = min(C[j], l[i] + r[i] - H[i]); } } return C; } /* 4 2 2 4 3 5 0 2 1 3 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...