#include <bits/stdc++.h>
#include "meetings.h"
#define vecint vector<int>
using namespace std;
long long cost_at(vecint& H, int L, int R, int x) {
int rmax = 0;
long long acc = 0;
for (int i = x; i <= R; i++) {
rmax = max(rmax, H[i]);
acc += rmax;
}
int lmax = 0;
for (int i = x; i >= L; i--) {
lmax = max(lmax, H[i]);
acc += lmax;
}
acc -= H[x];
return acc;
}
long long minimum_cost(vecint& H, int L, int R) {
long long minx_val = INT64_MAX;
int minx = -1;
for (int i = L; i <= R; i++) {
if (minx_val >= cost_at(H, L, R, i)) {
minx = i;
}
minx_val = min(minx_val, cost_at(H, L, R, i));
}
// cout << minx << endl;
return minx_val;
}
vector<long long> minimum_costs(vecint H, vecint L, vecint R) {
vector<long long> mins;
mins.reserve(L.size());
for (int i = 0; i < L.size(); i++) {
mins.push_back(minimum_cost(H, L[i], R[i]));
}
return mins;
}
Compilation message
meetings.cpp: In function 'long long int minimum_cost(std::vector<int>&, int, int)':
meetings.cpp:24:9: warning: variable 'minx' set but not used [-Wunused-but-set-variable]
24 | int minx = -1;
| ^~~~
meetings.cpp: In function 'std::vector<long long int> minimum_costs(std::vector<int>, std::vector<int>, std::vector<int>)':
meetings.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (int i = 0; i < L.size(); i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
18 ms |
340 KB |
Output is correct |
3 |
Correct |
111 ms |
332 KB |
Output is correct |
4 |
Correct |
35 ms |
332 KB |
Output is correct |
5 |
Correct |
113 ms |
336 KB |
Output is correct |
6 |
Correct |
12 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
5 ms |
344 KB |
Output is correct |
9 |
Correct |
115 ms |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
18 ms |
340 KB |
Output is correct |
3 |
Correct |
111 ms |
332 KB |
Output is correct |
4 |
Correct |
35 ms |
332 KB |
Output is correct |
5 |
Correct |
113 ms |
336 KB |
Output is correct |
6 |
Correct |
12 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
5 ms |
344 KB |
Output is correct |
9 |
Correct |
115 ms |
308 KB |
Output is correct |
10 |
Execution timed out |
5559 ms |
620 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Execution timed out |
5582 ms |
1740 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Execution timed out |
5582 ms |
1740 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
18 ms |
340 KB |
Output is correct |
3 |
Correct |
111 ms |
332 KB |
Output is correct |
4 |
Correct |
35 ms |
332 KB |
Output is correct |
5 |
Correct |
113 ms |
336 KB |
Output is correct |
6 |
Correct |
12 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
5 ms |
344 KB |
Output is correct |
9 |
Correct |
115 ms |
308 KB |
Output is correct |
10 |
Execution timed out |
5559 ms |
620 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |