This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
vector<long long> minimum_costs (vector<int> h, vector<int> l, vector<int> r) {
int n = h.size(), q = l.size();
vector<long long> ans(q, 1e18);
for(int i = 0; i < q; i++) {
for(int x = l[i]; x <= r[i]; x++) {
long long cost = h[x];
for(int y = x - 1, mx = h[x]; y >= l[i]; y--) {
mx = max(mx, h[y]);
cost += mx;
}
for(int y = x + 1, mx = h[x]; y <= r[i]; y++) {
mx = max(mx, h[y]);
cost += mx;
}
ans[i] = min(ans[i], cost);
}
}
// for(int i = 0; i < q; i++) cout << ans[i] << endl;
return ans;
}
#ifdef ngu
int main() {
freopen ("task.inp", "r", stdin);
freopen ("task.out", "w", stdout);
int n, q; cin >> n >> q;
vector<int> h(n), l(q), r(q);
for(int i = 0; i < n; i++) cin >> h[i];
for(int i = 0; i < q; i++) cin >> l[i] >> r[i];
minimum_costs(h, l, r);
}
#endif // ngu
Compilation message (stderr)
meetings.cpp: In function 'std::vector<long long int> minimum_costs(std::vector<int>, std::vector<int>, std::vector<int>)':
meetings.cpp:9:7: warning: unused variable 'n' [-Wunused-variable]
9 | int n = h.size(), q = l.size();
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |