답안 #225182

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
225182 2020-04-19T11:52:46 Z Vimmer Simfonija (COCI19_simfonija) C++14
55 / 110
77 ms 2808 KB
#include <bits/stdc++.h>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 200005
#define MOD ll(998244353)

using namespace std;

typedef long long ll;

typedef long double ld;




int main()
{

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    ll n, k;

    cin >> n >> k;

    ll a[n], b[n];

    for (ll i = 0; i < n; i++) cin >> a[i];

    for (ll i = 0; i < n; i++) cin >> b[i];

    vector <ll> g(n);

    for (ll i = 0; i < n; i++) g[i] = a[i] - b[i];

    sort(g.begin(), g.end());

    ll mid = (n - k) / 2;

    ll ans = 1e18;

    mid -= 100;

    for (int i = 0; i <= 200; i++)
    {
        mid++;

        if (mid >= 0 && mid < n)
        {
            ll x = -g[mid], sum = 0;

            for (int j = 0; j < n - k; j++) sum += abs(g[j] + x);

            ans = min(ans, sum);
        }

        if (k + mid >= 0 && mid + k < n)
        {
            ll x = -g[k + mid], sum = 0;

            for (int j = k; j < n; j++) sum += abs(g[j] + x);

            ans = min(ans, sum);
        }
    }

    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 2688 KB Output is correct
2 Correct 70 ms 2680 KB Output is correct
3 Correct 68 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 2808 KB Output is correct
2 Correct 77 ms 2680 KB Output is correct
3 Correct 71 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 2688 KB Output is correct
2 Correct 71 ms 2688 KB Output is correct
3 Correct 71 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 2680 KB Output is correct
2 Correct 45 ms 2688 KB Output is correct
3 Incorrect 52 ms 2688 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 2688 KB Output is correct
2 Incorrect 56 ms 2680 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 67 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 2688 KB Output is correct
2 Incorrect 38 ms 2720 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 2688 KB Output is correct
2 Correct 70 ms 2808 KB Output is correct
3 Correct 66 ms 2688 KB Output is correct