답안 #100236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
100236 2019-03-10T02:05:34 Z FutymyClone Simfonija (COCI19_simfonija) C++14
44 / 110
430 ms 2352 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

int n, m, a[N], b[N];

long long solve (int x) {
    vector <int> vec;
    for (int i = 1; i <= n; i++) vec.push_back(abs(a[i] + x - b[i]));
    sort(vec.begin(), vec.end(), greater <int>());

    long long ans = 0;
    for (int i = m; i < vec.size(); i++) ans += vec[i];
    return ans;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> b[i];

    int l = -5e6, r = 5e6, ans = -1e9;
    while (l <= r) {
        int mid = (l + r) / 2;
        long long lef = solve(mid), rig = solve(mid + 1);
        if (lef == rig) {
            ans = mid;
            break;
        }

        if (lef < rig) r = mid - 1;
        else l = mid + 1;
    }

    if (ans < -5e8) ans = l;
    cout << solve(ans);
    return 0;
}

Compilation message

simfonija.cpp: In function 'long long int solve(int)':
simfonija.cpp:15:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = m; i < vec.size(); i++) ans += vec[i];
                     ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 375 ms 2144 KB Output is correct
2 Correct 305 ms 2148 KB Output is correct
3 Correct 215 ms 2076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 401 ms 2108 KB Output is correct
2 Correct 295 ms 2068 KB Output is correct
3 Correct 223 ms 2212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 400 ms 2352 KB Output is correct
2 Correct 291 ms 2228 KB Output is correct
3 Correct 248 ms 2184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 179 ms 2156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 430 ms 2280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 180 ms 2092 KB Output is correct
2 Correct 254 ms 2176 KB Output is correct
3 Incorrect 374 ms 2140 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 296 ms 2128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 380 ms 2196 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 277 ms 2160 KB Output isn't correct
2 Halted 0 ms 0 KB -