이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
using namespace std;
#include <iostream>
#include <stack>
#include <algorithm>
#define MAXN 100005
int counter[4000005],A[MAXN],B[MAXN],arr[MAXN],N,K;
int main() {
cin >> N >> K;
long long sum = 0;
for(int i = 0;i < N;++i) cin >> A[i];
for(int i = 0;i < N;++i) cin >> B[i];
for(int i = 0;i < N;++i) {
arr[i] = A[i] - B[i] + 2000001;
counter[arr[i]]++;
sum += arr[i];
}
sort(arr,arr + N);
stack<int> s;
for(int i = 0;i < K;++i) {
s.push(N - i - 1);
sum -= arr[N - i - 1];
}
long long ans = sum;
int inc = 0;
int ptr = 0;
for(int i = 0;i < 4000005;++i) {
inc += counter[i];
sum += inc - (N - K - inc);
while(!s.empty() && (arr[s.top()] - i - 1) < (i + 1 - arr[ptr])) {
sum += arr[s.top()] - arr[ptr++] - 2 * i - 2;
inc--;
s.pop();
}
ans = min(ans,sum);
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |