#include <bits/stdc++.h>
#define ve vector
#define pb push_back
#define ar array
#define ll long long
#define sz(x) (int)(x.size())
using namespace std;
ve<ll> calculate_costs(ve<int> W, ve<int> A, ve<int> B, ve<int> Q) {
ve<ll> ans;
int N = sz(W);
array<int, 2> W2[N];
for(int i = 0; i < N; i++) {
W2[i] = {W[i], i};
}
sort(W2, W2 + N);
for(int diff : Q) {
ll tc = 0;
ve<ve<int>> ccs;
ve<int> curcc;
for(int i = 0; i < N; i++) {
if(i != 0 && W2[i][0] - W2[i - 1][0] > diff) {
ccs.pb(curcc);
ve<int> nc;
curcc = nc;
}
curcc.pb(i);
}
ccs.pb(curcc);
for(auto i : ccs) {
ll tb = 0;
for(int j : i) {
int idx = W2[j][1];
tb += B[idx];
}
if(sz(i) % 2) {
int sz_cc = sz(i);
int idxone = W2[i[0]][1];
int idxn = W2[i[sz_cc - 1]][1];
ll mi = tb + min(A[idxone] - B[idxone], A[idxn] - B[idxn]);
for(int j = 1; j < sz_cc - 1; j++) {
if(W2[i[j + 1]][0] - W2[i[j - 1]][0] <= diff) {
int idx = W2[i[j]][1];
mi = min(mi, tb - B[idx] + A[idx]);
}
}
tb = mi;
}
tc += tb;
}
ans.pb(tc);
}
return ans;
}
// int main() {
// int N;
// cin >> N;
//
// ve<int> w;
// ve<int> a;
// ve<int> b;
// ve<int> q;
// for(int i = 0; i < N; i++) {
// int x, y, z;
// cin >> x >> y >> z;
// w.pb(x);
// a.pb(y);
// b.pb(z);
// }
// int Q;
// cin >> Q;
// for(int i = 0; i < Q; i++) {
// int x;
// cin >> x;
// q.pb(x);
// }
//
// calculate_costs(w, a, b, q);
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
592 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 |
508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
7116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
8324 KB |
Output is correct |
2 |
Correct |
39 ms |
8156 KB |
Output is correct |
3 |
Correct |
43 ms |
8008 KB |
Output is correct |
4 |
Correct |
47 ms |
8124 KB |
Output is correct |
5 |
Correct |
37 ms |
7428 KB |
Output is correct |
6 |
Correct |
47 ms |
12324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
592 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 |
508 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Incorrect |
2 ms |
592 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
592 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 |
508 KB |
Output is correct |
7 |
Incorrect |
31 ms |
7116 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
8324 KB |
Output is correct |
2 |
Correct |
39 ms |
8156 KB |
Output is correct |
3 |
Correct |
43 ms |
8008 KB |
Output is correct |
4 |
Correct |
47 ms |
8124 KB |
Output is correct |
5 |
Correct |
37 ms |
7428 KB |
Output is correct |
6 |
Correct |
47 ms |
12324 KB |
Output is correct |
7 |
Execution timed out |
2041 ms |
10260 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
592 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 |
508 KB |
Output is correct |
8 |
Incorrect |
31 ms |
7116 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |