Submission #105063

# Submission time Handle Problem Language Result Execution time Memory
105063 2019-04-10T12:15:09 Z polyfish Simfonija (COCI19_simfonija) C++14
0 / 110
40 ms 4248 KB
//Pantyhose(black) + glasses = infinity

#include <bits/stdc++.h>
using namespace std;
 
#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) {cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define FILE_NAME "data"

const int MAX_N = 100002;
const int64_t INF = 1e18;

int n, k, a[MAX_N], b[MAX_N];
int64_t p[MAX_N], ps[MAX_N];

void read_input() {
	cin >> n >> k;
	k = n - k;

	for (int i=1; i<=n; ++i)
		cin >> a[i];

	for (int i=1; i<=n; ++i)
		cin >> b[i];
}

int64_t get(int l, int r) {
	if (l==0)
		return ps[r];
	return ps[r] - ps[l-1];
}

int64_t calc(int64_t x, int l, int r) {
	return p[x] * (x - l + 1) - (ps[x]-ps[l-1]) + ps[r]-ps[x] - p[x] * (r - x);
}

void solve() {
	for (int i=1; i<=n; ++i) {
		p[i] = b[i]-a[i];
		ps[i] = ps[i-1] + p[i];
	}

	sort(p+1, p+n+1);

	int cur = 1;
	int64_t res = INF;

	// debug(calc(1, 1, 3));
	for (int i=1; i+k-1<=n; ++i) {
		while (cur+1<i+k && calc(cur+1, i, i+k-1)<calc(cur, i, i+k-1))
			++cur;
		res = min(res, calc(cur, i, i+k-1));
	}

	cout << res;
}

int main() {
	#ifdef GLASSES_GIRL
		freopen(FILE_NAME".in", "r", stdin);
		freopen(FILE_NAME".out", "w", stdout);
	#endif
	ios::sync_with_stdio(0); cin.tie(0);

	read_input();
	solve();
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 4088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 4216 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 4248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 3428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 4116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 4088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 4088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 4088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 4088 KB Output isn't correct
2 Halted 0 ms 0 KB -