답안 #225035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
225035 2020-04-19T08:18:15 Z Vimmer Simfonija (COCI19_simfonija) C++14
77 / 110
699 ms 4076 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 = 1000000;

    int q = 0;

    while (q < 30)
    {
        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));

    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 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 640 ms 3872 KB Output is correct
2 Correct 501 ms 3868 KB Output is correct
3 Correct 338 ms 3776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 648 ms 4076 KB Output is correct
2 Correct 498 ms 3844 KB Output is correct
3 Correct 340 ms 3788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 640 ms 3832 KB Output is correct
2 Correct 489 ms 3836 KB Output is correct
3 Correct 345 ms 3936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 267 ms 3792 KB Output is correct
2 Correct 288 ms 3904 KB Output is correct
3 Correct 391 ms 3892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 686 ms 3884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 265 ms 3796 KB Output is correct
2 Incorrect 393 ms 3780 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 680 ms 3980 KB Output is correct
2 Correct 395 ms 3784 KB Output is correct
3 Correct 689 ms 3940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 617 ms 3788 KB Output is correct
2 Incorrect 699 ms 4052 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 394 ms 3804 KB Output is correct
2 Correct 401 ms 4016 KB Output is correct
3 Correct 676 ms 3832 KB Output is correct