Submission #100282

# Submission time Handle Problem Language Result Execution time Memory
100282 2019-03-10T08:42:18 Z FutymyClone Simfonija (COCI19_simfonija) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
long long oo = 1e18;
int n, k;
int a[100001], b[100001], c[100001], d[100001];
long long solve(int x){
    for(int i=1;i<=n;i++) d[i] = c[i]+x;
    int l = 1, r = n, cnt = 0;
    while(cnt < k){
        cnt++;
        if(abs(d[l]) > abs(d[r])) d[l] = 0, l++;
        else d[r] = 0, r--;
    }
    long long ans = 0;
    for(int i=1;i<=n;i++) ans += abs(d[i]);
    return ans;
}
int main(){
    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]);
    for(int i=1;i<=n;i++) c[i] = a[i]-b[i];
    sort(c+1, c+1+n);
    int lo = -5e6, hi = 5e6;
    long long ans = oo;
    for(int i=0;i<100;i++){
        int mid1 = lo + (hi-lo)/3;
        int mid2 = hi - (hi-lo)/3;
        long long result1 = solve(mid1);
        long long result2 = solve(mid2);
        if(result1 < result2){
            ans = min(ans, result1);
            hi = mid2;
        }
        else{
            ans = min(ans, result2);
            lo = mid1;
        }
    }
    lo = -5e6, hi = 5e6;
    for(int i=0;i<100;i++){
        int mid1 = lo + (hi-lo)/3;
        int mid2 = hi - (hi-lo)/3;
        long long result1 = solve(-mid1);
        long long result2 = solve(-mid2);
        if(result1 < result2){
            ans = min(ans, result1);
            hi = mid2;
        }
        else{
            ans = min(ans, result2);
            lo = mid1;
        }
    }
    printf("%lld\n", ans);
}

Compilation message

simfonija.cpp:24:2: error: stray '\302' in program
     int lo = -5e6, hi = 5e6;
  ^
simfonija.cpp:24:3: error: stray '\240' in program
     int lo = -5e6, hi = 5e6;
   ^
simfonija.cpp:24:5: error: stray '\302' in program
     int lo = -5e6, hi = 5e6;
     ^
simfonija.cpp:24:6: error: stray '\240' in program
     int lo = -5e6, hi = 5e6;
      ^
simfonija.cpp:40:2: error: stray '\302' in program
     lo = -5e6, hi = 5e6;
  ^
simfonija.cpp:40:3: error: stray '\240' in program
     lo = -5e6, hi = 5e6;
   ^
simfonija.cpp:40:5: error: stray '\302' in program
     lo = -5e6, hi = 5e6;
     ^
simfonija.cpp:40:6: error: stray '\240' in program
     lo = -5e6, hi = 5e6;
      ^
simfonija.cpp: In function 'int main()':
simfonija.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~
simfonija.cpp:20:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++) scanf("%d", &a[i]);
                           ~~~~~^~~~~~~~~~~~~
simfonija.cpp:21:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++) scanf("%d", &b[i]);
                           ~~~~~^~~~~~~~~~~~~