Submission #100605

# Submission time Handle Problem Language Result Execution time Memory
100605 2019-03-12T19:44:17 Z kraljlavova1 Simfonija (COCI19_simfonija) C++11
44 / 110
55 ms 7176 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
const int MAXN = 1e5 + 10, MAX = 2e6 + 10;
int n, k, dif, dsol;
int a[MAXN], b[MAXN];
int s[2 * MAX];
ll cur, sol = 4e18;
vector<int> vd;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	cin >> n >> k;
	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++){
		s[b[i] - a[i] + 1 + MAX] += 2;
	}
	for(int i = 0;i < n; i++){
		int p = a[i] - MAX;
		cur += b[i] - p + 1;
	}
	dif = -n;
	for(int i = -MAX;i < MAX; i++){
		dif += s[i + MAX];
		cur += dif;
		if(cur < sol){
			sol = cur;
			dsol = i;
		}
	}
	for(int i = 0;i < n; i++){
		a[i] += dsol;
		vd.push_back(abs(b[i] - a[i]));
	}
	sort(vd.begin(), vd.end());
	reverse(vd.begin(), vd.end());
	for(int i = 0;i < min(k, (int)vd.size()); i++){
		sol -= vd[i];
	}
	cout << sol << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 384 KB Output is correct
2 Correct 9 ms 384 KB Output is correct
3 Correct 10 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 7136 KB Output is correct
2 Correct 43 ms 4784 KB Output is correct
3 Correct 36 ms 3192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 7032 KB Output is correct
2 Correct 38 ms 4772 KB Output is correct
3 Correct 38 ms 3292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 7172 KB Output is correct
2 Correct 42 ms 4700 KB Output is correct
3 Correct 35 ms 3200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2560 KB Output is correct
2 Correct 35 ms 3192 KB Output is correct
3 Incorrect 35 ms 3456 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 7168 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 3192 KB Output is correct
2 Incorrect 42 ms 3320 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 7160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 7176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 3448 KB Output isn't correct
2 Halted 0 ms 0 KB -