Submission #314100

# Submission time Handle Problem Language Result Execution time Memory
314100 2020-10-18T10:48:01 Z phathnv Simfonija (COCI19_simfonija) C++11
22 / 110
46 ms 3448 KB
#include <bits/stdc++.h>

#define mp make_pair
#define X first
#define Y second
#define taskname "SIMFONIJA"

using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

const int N = 1e5 + 1;

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

void readInput(){
    scanf("%d %d", &n, &k);
    for(int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    for(int i = 1; i <= n; i++)
        scanf("%d", &b[i]);
}

void solve(){
    if (n == k){
        printf("0");
        return;
    }
    for(int i = 1; i <= n; i++)
        a[i] -= b[i];
    sort(a + 1, a + 1 + n);
    for(int i = 1; i <= n; i++)
        s[i] = s[i - 1] + a[i];

    ll res = 1e18;
    for(int i = 0; i <= k; i++){
        int l = i + 1;
        int r = n - (k - i);
        int mid = (l + r) >> 1;
        res = min(res, (ll) a[mid] * (mid - l + 1) - (s[mid] - s[l - 1]) + (s[r] - s[mid]) - (ll) a[mid] * (r - mid));
    }
    printf("%I64d", res);
}

int main(){
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    readInput();
    solve();
    return 0;
}

Compilation message

simfonija.cpp: In function 'void solve()':
simfonija.cpp:44:17: warning: format '%d' expects argument of type 'int', but argument 2 has type 'll' {aka 'long long int'} [-Wformat=]
   44 |     printf("%I64d", res);
      |             ~~~~^   ~~~
      |                 |   |
      |                 int ll {aka long long int}
      |             %I64lld
simfonija.cpp: In function 'void readInput()':
simfonija.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
simfonija.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
simfonija.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |         scanf("%d", &b[i]);
      |         ~~~~~^~~~~~~~~~~~~
simfonija.cpp: In function 'int main()':
simfonija.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   49 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
simfonija.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   50 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 3320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 3320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 3320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 2680 KB Output is correct
2 Correct 34 ms 3328 KB Output is correct
3 Correct 36 ms 3320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 3320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 3320 KB Output is correct
2 Incorrect 36 ms 3320 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 3448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 3312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 3320 KB Output isn't correct
2 Halted 0 ms 0 KB -