#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector <ll> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E) {
int N = W.size(), Q = E.size();
vector <tuple <int, int, int>> items;
for (int i = 0; i < N; i++) items.push_back(make_tuple(W[i], A[i], B[i]));
sort(items.begin(), items.end());
for (int i = 0; i < N; ++i) {
auto [w, a, b] = items[i];
W[i] = w, A[i] = a, B[i] = b;
}
vector <ll> ans;
for(int q = 0; q < Q; q++){
ll d = E[q];
vector<ll> dp(N + 1, INT_MAX);
for(int i = 0; i < N; ++i){
if(i == 0) dp[i] = A[i];
else if(i == 1){
if(W[i] - W[i - 1] <= d) dp[i] = B[i] + B[i - 1];
else dp[i] = dp[i - 1] + A[i];
}
else{
dp[i] = dp[i - 1] + A[i];
if(W[i] - W[i - 1] <= d) dp[i] = min(dp[i], (ll)(B[i] + B[i - 1] + dp[i - 2]));
if(W[i] - W[i - 2] <= d){
if(i >= 3) dp[i] = min(dp[i], (ll)(B[i] + A[i - 1] + B[i - 2] + dp[i - 3]));
else dp[i] = min(dp[i], (ll)(B[i] + A[i - 1] + B[i - 2]));
}
}
}
ans.push_back(dp[N - 1]);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
7104 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
5956 KB |
Output is correct |
2 |
Correct |
30 ms |
6160 KB |
Output is correct |
3 |
Correct |
31 ms |
6088 KB |
Output is correct |
4 |
Correct |
30 ms |
6088 KB |
Output is correct |
5 |
Correct |
32 ms |
6080 KB |
Output is correct |
6 |
Correct |
30 ms |
6220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
5956 KB |
Output is correct |
2 |
Correct |
30 ms |
6160 KB |
Output is correct |
3 |
Correct |
31 ms |
6088 KB |
Output is correct |
4 |
Correct |
30 ms |
6088 KB |
Output is correct |
5 |
Correct |
32 ms |
6080 KB |
Output is correct |
6 |
Correct |
30 ms |
6220 KB |
Output is correct |
7 |
Execution timed out |
2054 ms |
7284 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
2 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |