답안 #225032

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
225032 2020-04-19T08:17:03 Z Vimmer Simfonija (COCI19_simfonija) C++14
11 / 110
1000 ms 4104 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 100005
#define MOD ll(998244353)

using namespace std;

typedef long long ll;

typedef long double ld;


ll a[N], b[N], n, k;

ll calc(ll x)
{
    ll sum = 0;

    vector <ll> g; g.clear();

    for (int i = 0; i < n; i++) g.pb(abs((a[i] + x) - b[i]));

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

    int kk = k;

    while (kk > 0)
    {
        kk--;

        g.pop_back();
    }

    for (int i = 0; i < sz(g); i++) sum += g[i];

    return sum;
}
int main()
{

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

    cin >> n >> k;

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

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

    int l = -1000000, r = 0;

    int q = 0;

    while (q < 25)
    {
        int mdl = l + (r - l) / 3;

        int mdr = r - (r - l) / 3;

        if (calc(mdl) > calc(mdr)) l = mdl; else r = mdr;

        q++;
    }

    ll ans = 1e18;

    for (int i = l; i <= r; i++) ans = min(ans, calc(i));

    l = 0; r = 1000000;

    q = 0;

    while (q < 25)
    {
        int mdl = l + (r - l) / 3;

        int mdr = r - (r - l) / 3;

        if (calc(mdl) > calc(mdr)) l = mdl; else r = mdr;

        q++;
    }

    for (int i = l; i <= r; i++) ans = min(ans, calc(i));

    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1080 ms 4056 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1084 ms 3856 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1077 ms 3860 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 589 ms 3972 KB Output is correct
2 Incorrect 594 ms 3800 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1088 ms 3964 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 579 ms 3960 KB Output is correct
2 Incorrect 889 ms 3788 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1095 ms 3812 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 3824 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 920 ms 3944 KB Output is correct
2 Correct 898 ms 3892 KB Output is correct
3 Execution timed out 1092 ms 4104 KB Time limit exceeded