Submission #1006824

# Submission time Handle Problem Language Result Execution time Memory
1006824 2024-06-24T09:06:36 Z Whisper Simfonija (COCI19_simfonija) C++17
44 / 110
32 ms 6820 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPD(i, n) for (int i = (n) - 1; i >= 0; --i)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)


constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
    Phu Trong from Nguyen Tat Thanh High School for gifted student
*/

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
#define MAX     100005

int nArr, k;
int A[MAX], B[MAX];


int solve(int x){
    int ans = INF;
    vector<int> C(nArr + 5);
    FOR(i, 1, nArr) C[i] = A[i] + x;
    int sum = 0;
    vector<int> store;
    FOR(i, 1, nArr) sum += abs(B[i] - C[i]), store.push_back(abs(B[i] - C[i]));
    sort(store.rbegin(), store.rend());
    for (int i = 0; i < k; ++i) sum -= store[i];
    return sum;
}
void process(void){
    cin >> nArr >> k;
    for (int i = 1; i <= nArr; ++i) cin >> A[i];
    for (int i = 1; i <= nArr; ++i) cin >> B[i];
    vector<int> x; x.push_back(0);
    for (int i = 1; i <= nArr; ++i){
        x.push_back(B[i] - A[i]);
    }
    sort(x.begin() + 1, x.end());

    int ans = min(solve(x[nArr / 2]), solve(x[(nArr + 1) / 2]));
    cout << ans;
}

signed main(){
    #define name "Whisper"
    cin.tie(nullptr) -> sync_with_stdio(false);
    ///freopen(name".inp", "r", stdin);
    ///freopen(name".out", "w", stdout);

    process();
}




Compilation message

simfonija.cpp: In function 'long long int solve(long long int)':
simfonija.cpp:45:9: warning: unused variable 'ans' [-Wunused-variable]
   45 |     int ans = INF;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 5180 KB Output is correct
2 Correct 26 ms 6728 KB Output is correct
3 Correct 20 ms 6708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 5168 KB Output is correct
2 Correct 26 ms 6716 KB Output is correct
3 Correct 21 ms 6792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 5180 KB Output is correct
2 Correct 27 ms 6708 KB Output is correct
3 Correct 21 ms 6820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 5180 KB Output is correct
2 Correct 19 ms 5176 KB Output is correct
3 Incorrect 22 ms 6716 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 5172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 5180 KB Output is correct
2 Incorrect 24 ms 5172 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 5312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 5176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 5180 KB Output isn't correct
2 Halted 0 ms 0 KB -