#include <bits/stdc++.h>
#include "nile.h"
using namespace std;
typedef long long ll;
vector<ll> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E) {
int Q = (int)E.size();
int N=(int)W.size();
vector<ll>ans;
vector<tuple<int,int,int>>ordenar;
for(int i=0;i<N;i++){
ordenar.push_back({W[i],B[i],A[i]});
}
sort(ordenar.begin(),ordenar.end());
W.clear();
A.clear();
B.clear();
for(auto[w,b,a]:ordenar){
A.push_back(a);
B.push_back(b);
W.push_back(w);
}
for(int e=0;e<Q;e++){
int d=E[e];
vector<ll>dp(N,LLONG_MAX);
for(int i=0;i<N;i++){
if(i==0){
dp[i]=A[i];
}
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]);
}
}
if(i>=2){
dp[i]=((ll)A[i]+dp[i-1]);
if((W[i]-W[i-1])<=d){
dp[i]=min(dp[i],(ll)((ll)B[i]+(ll)B[i-1]+dp[i-2]));
}
if((W[i]-W[i-2])<=d){
if(i>=3){
dp[i]=min(dp[i],(ll)((ll)B[i]+(ll)B[i-2]+(ll)A[i-1]+dp[i-3]));
}
else{
dp[i]=min(dp[i],(ll)((ll)B[i]+(ll)B[i-2]+(ll)A[i-1]));
}
}
}
}
ans.push_back(dp[N-1]);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
4800 KB |
Output is correct |
2 |
Correct |
33 ms |
6384 KB |
Output is correct |
3 |
Correct |
30 ms |
6336 KB |
Output is correct |
4 |
Correct |
29 ms |
4800 KB |
Output is correct |
5 |
Correct |
29 ms |
6600 KB |
Output is correct |
6 |
Correct |
28 ms |
4808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
4800 KB |
Output is correct |
2 |
Correct |
27 ms |
4808 KB |
Output is correct |
3 |
Correct |
30 ms |
5824 KB |
Output is correct |
4 |
Correct |
29 ms |
5056 KB |
Output is correct |
5 |
Correct |
29 ms |
4808 KB |
Output is correct |
6 |
Correct |
30 ms |
4800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
31 ms |
4800 KB |
Output is correct |
8 |
Correct |
33 ms |
6384 KB |
Output is correct |
9 |
Correct |
30 ms |
6336 KB |
Output is correct |
10 |
Correct |
29 ms |
4800 KB |
Output is correct |
11 |
Correct |
29 ms |
6600 KB |
Output is correct |
12 |
Correct |
28 ms |
4808 KB |
Output is correct |
13 |
Correct |
34 ms |
4800 KB |
Output is correct |
14 |
Correct |
27 ms |
4808 KB |
Output is correct |
15 |
Correct |
30 ms |
5824 KB |
Output is correct |
16 |
Correct |
29 ms |
5056 KB |
Output is correct |
17 |
Correct |
29 ms |
4808 KB |
Output is correct |
18 |
Correct |
30 ms |
4800 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
40 ms |
4800 KB |
Output is correct |
26 |
Correct |
33 ms |
4804 KB |
Output is correct |
27 |
Correct |
34 ms |
4804 KB |
Output is correct |
28 |
Correct |
35 ms |
4796 KB |
Output is correct |
29 |
Correct |
42 ms |
4856 KB |
Output is correct |
30 |
Correct |
34 ms |
4808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
4800 KB |
Output is correct |
2 |
Correct |
27 ms |
4808 KB |
Output is correct |
3 |
Correct |
30 ms |
5824 KB |
Output is correct |
4 |
Correct |
29 ms |
5056 KB |
Output is correct |
5 |
Correct |
29 ms |
4808 KB |
Output is correct |
6 |
Correct |
30 ms |
4800 KB |
Output is correct |
7 |
Execution timed out |
2057 ms |
5628 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
31 ms |
4800 KB |
Output is correct |
9 |
Correct |
33 ms |
6384 KB |
Output is correct |
10 |
Correct |
30 ms |
6336 KB |
Output is correct |
11 |
Correct |
29 ms |
4800 KB |
Output is correct |
12 |
Correct |
29 ms |
6600 KB |
Output is correct |
13 |
Correct |
28 ms |
4808 KB |
Output is correct |
14 |
Correct |
34 ms |
4800 KB |
Output is correct |
15 |
Correct |
27 ms |
4808 KB |
Output is correct |
16 |
Correct |
30 ms |
5824 KB |
Output is correct |
17 |
Correct |
29 ms |
5056 KB |
Output is correct |
18 |
Correct |
29 ms |
4808 KB |
Output is correct |
19 |
Correct |
30 ms |
4800 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
2 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
40 ms |
4800 KB |
Output is correct |
27 |
Correct |
33 ms |
4804 KB |
Output is correct |
28 |
Correct |
34 ms |
4804 KB |
Output is correct |
29 |
Correct |
35 ms |
4796 KB |
Output is correct |
30 |
Correct |
42 ms |
4856 KB |
Output is correct |
31 |
Correct |
34 ms |
4808 KB |
Output is correct |
32 |
Execution timed out |
2057 ms |
5628 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |