Submission #103587

#TimeUsernameProblemLanguageResultExecution timeMemory
103587kishtarn555Simfonija (COCI19_simfonija)C++14
11 / 110
1086 ms2724 KiB
#include<iostream> #include<math.h> #include<stdlib.h> #include<algorithm> using namespace std; int N,M, K; long long a[100000]; long long b[100000]; long long differ[100000]; long long aab(long long x) { if (x < 0)return -x; return x; } long long eval(long long x) { int ini=0,fini=N; if (x < 0) { ini =K; } else { fini = N-K; } long long s= 0; for (int i = ini; i < fini; i++) { if (K!=0) { s+=aab(differ[i]+x); } else { s+=aab((a[i]+x)-b[i]); } } return s; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >>N>>K; for (int i= 0; i < N; i ++) { cin >> a[i]; } for (int i= 0; i < N; i ++) { cin >> b[i]; differ[i]=a[i]-b[i]; } // return 0; sort(differ,differ+N); // return 0; long long best=eval(0); for (int i = -2e5; i <=2e5; i++) { best=min(best,eval(i)); } cout << best; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...