Submission #653002

#TimeUsernameProblemLanguageResultExecution timeMemory
653002StickfishDungeon 3 (JOI21_ho_t5)C++17
11 / 100
4051 ms6368 KiB
#include <iostream> #include <vector> #include <deque> using namespace std; using ll = long long; const int MAXN = 2e5 + 123; ll eng[MAXN]; ll cost[MAXN]; ll get_ans(int l, int r, int mxeng) { deque<pair<ll, ll>> dq; ll eng_total = 0; ll ans = 0; for (int i = l; i < r; ++i) { while (dq.size() && dq.back().first >= cost[i]) { eng_total -= dq.back().second; dq.pop_back(); } if (eng_total < mxeng) dq.push_back({cost[i], mxeng - eng_total}); eng_total = mxeng; if (eng[i] > eng_total) { return -1; } ll eng_need = eng[i]; while (eng_need > 0) { if (eng_need >= dq.front().second) { eng_need -= dq.front().second; ans += dq.front().first * dq.front().second; eng_total -= dq.front().second; dq.pop_front(); } else { dq.front().second -= eng_need; ans += dq.front().first * eng_need; eng_total -= eng_need; eng_need = 0; } } } return ans; } signed main() { int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) { cin >> eng[i]; } for (int i = 0; i < n; ++i) { cin >> cost[i]; } while (m--) { int l, r, mxeng; cin >> l >> r >> mxeng; --l, --r; cout << get_ans(l, r, mxeng) << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...