답안 #225049

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
225049 2020-04-19T08:31:42 Z kartel Simfonija (COCI19_simfonija) C++14
77 / 110
799 ms 3920 KB
#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
#define M ll(998244353)
#define inf ll(2e9+7)
#define N ll(200500)
#define sz(x) x.size()
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
#define el '\n'
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> os;

ll a[N], b[N], i, n, k, c[N], l, r;

bool cmp(int a, int b) {return (a > b);}

ll ans(ll x)
{
    vector <int> p;

    ll kl = 0;

    for (i = 1; i <= n; i++) c[i] = a[i] + x;

    for (i = 1; i <= n; i++) p.pb(abs(c[i] - b[i])), kl += abs(c[i] - b[i]);

    sort(p.begin(), p.end(), cmp);

    i = 0;
    while (i < k) kl -= p[i], i++;

    return kl;
}

int main()
{
//    in("input.txt");
//    out("output.txt");

    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for (i = 1; i <= n; i++) cin >> a[i];
    for (i = 1; i <= n; i++) cin >> b[i];

    l = -1e6;
    r = 1e6;

    while (r - l > 10)
    {
        int m1 = l + (r - l) / 3;
        int m2 = r - (r - l) / 3;

        if (ans(m1) > ans(m2)) l = m1;
                          else r = m2;
    }

    ll an = 1e18;

    for (; l <= r; l++) an = min(an, ans(l));

    cout << an;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 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 Correct 758 ms 3752 KB Output is correct
2 Correct 583 ms 3712 KB Output is correct
3 Correct 420 ms 3672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 750 ms 3808 KB Output is correct
2 Correct 643 ms 3668 KB Output is correct
3 Correct 424 ms 3892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 736 ms 3756 KB Output is correct
2 Correct 574 ms 3724 KB Output is correct
3 Correct 434 ms 3736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 363 ms 3668 KB Output is correct
2 Correct 372 ms 3712 KB Output is correct
3 Correct 482 ms 3656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 777 ms 3652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 362 ms 3788 KB Output is correct
2 Incorrect 483 ms 3716 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 790 ms 3840 KB Output is correct
2 Correct 481 ms 3836 KB Output is correct
3 Correct 779 ms 3752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 690 ms 3788 KB Output is correct
2 Incorrect 799 ms 3708 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 482 ms 3708 KB Output is correct
2 Correct 476 ms 3920 KB Output is correct
3 Correct 797 ms 3876 KB Output is correct