답안 #102558

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
102558 2019-03-25T23:07:14 Z Ort Simfonija (COCI19_simfonija) C++11
110 / 110
49 ms 860 KB
#include<iostream>
#include<vector>
#include<algorithm>
#define MAX 100020
#define ll long long
 
using namespace std;
 
int n, k, x, inc;
ll sol = 100000000000000000;

int a[MAX];
 
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	cin >> n >> x; k = n - x;
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=0;i<n;i++) {cin >> x; a[i]-=x;}
	sort(a, a+n);
	ll m = 0, c = 0, nc = 0, l, r;
	if(k%2) m = k / 2;
	else m = k / 2 - 1;
	int mv = a[m];
	for(int i=0;i<k;i++) c += abs(a[i]-mv);
	ll om = mv;
	sol = min(sol,c); inc++;
	for(int i=0;i<(n-k);i++) {
		mv = a[m+inc]; inc++;
		l = a[i]; r = a[i+k];
		nc = c - (abs(om-l)) + (abs(mv-r));
		if(k%2==0) nc -= (mv - om);
		sol = min(sol,nc);
		c = nc; om = mv;
	}
	cout << sol;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 768 KB Output is correct
2 Correct 30 ms 768 KB Output is correct
3 Correct 29 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 760 KB Output is correct
2 Correct 30 ms 768 KB Output is correct
3 Correct 28 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 768 KB Output is correct
2 Correct 27 ms 768 KB Output is correct
3 Correct 27 ms 740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 768 KB Output is correct
2 Correct 30 ms 740 KB Output is correct
3 Correct 37 ms 740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 756 KB Output is correct
2 Correct 32 ms 768 KB Output is correct
3 Correct 31 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 760 KB Output is correct
2 Correct 30 ms 768 KB Output is correct
3 Correct 30 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 768 KB Output is correct
2 Correct 34 ms 760 KB Output is correct
3 Correct 32 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 860 KB Output is correct
2 Correct 33 ms 768 KB Output is correct
3 Correct 49 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 768 KB Output is correct
2 Correct 26 ms 768 KB Output is correct
3 Correct 43 ms 732 KB Output is correct