#include "wiring.h"
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define pb push_back
const ll inf=1e9;
long long min_total_length(std::vector<int> r, std::vector<int> b) {
int n=r.size(),m=b.size();
ll res=0;
bool subtask2=false;if(r.back()<b[0]) subtask2=true;
if(subtask2){
for(int i=n-1,j=m-1;i>=0 || j>=0;){
if(i==-1 && j>0){
while(j>=0){
res+=b[j]-r[n-1];
j--;
}
break;
}
else if(i>0 && j==-1){
while(i>=0){
res+=b[0]-r[i];
i--;
}
break;
}
else{
res+=b[j]-r[i];
j--;
i--;
}
}
}
else{
if(n>m){
swap(n,m);
swap(r,b);
}
int best[m+10];
for(int i=0;i<m;i++){
best[i]=inf;
for(int j=0;j<n;j++){
best[i]=min(best[i],abs(b[i]-r[j]));
}
//printf("%i\n",best[i]);
}
res=inf;
for(int k=0;k<=n;k++){
ll ans=0;
vector<int>B;
for(int i=0;i<=m-1;i++){
if(i<k || i>=k+m-n) B.pb(b[i]);
}
/*printf("%i: ",k);
for(auto i:B) printf("%i ",i);
printf("\n");*/
for(int i=n-1;i>=0;i--){
ans+=abs(B[i]-r[i]);
}
for(int i=k;i<k+m-n;i++){
ans+=best[i];
}
res=min(res,ans);
}
/*for(int i=n-1,j=m-1;i>=0 || j>=0;){
if(i==-1){
break;
}
else if(j==-1){
break;
}
res+=abs(r[i]-b[j]);
}*/
}
/*ll dp[n+1][m+1];
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(r[i-1]>b[j-1]){
dp[]
}
else{
}
}
}*/
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '14340', found: '17422' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
12 ms |
3060 KB |
Output is correct |
4 |
Correct |
12 ms |
2936 KB |
Output is correct |
5 |
Correct |
12 ms |
2908 KB |
Output is correct |
6 |
Correct |
16 ms |
3780 KB |
Output is correct |
7 |
Correct |
16 ms |
3920 KB |
Output is correct |
8 |
Correct |
16 ms |
3932 KB |
Output is correct |
9 |
Correct |
16 ms |
3932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '17703', found: '19052' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
432 KB |
3rd lines differ - on the 1st token, expected: '27', found: '30' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '14340', found: '17422' |
3 |
Halted |
0 ms |
0 KB |
- |