Submission #318852

# Submission time Handle Problem Language Result Execution time Memory
318852 2020-11-03T10:19:12 Z neki Simfonija (COCI19_simfonija) C++14
55 / 110
96 ms 4224 KB
#include <bits/stdc++.h>
#define loop(i, a, b) for(long long i=a;i<b;i++)
#define pool(i, a, b) for(long long i=a-1;i>=b;i--)
#define fore(i, a) for(auto&& i:a)
#define fi first
#define se second
#define ps(a) push_back(a)
#define pb(a) pop_back(a)
#define sc scanf
#define vc vector
#define pa pair<ll, ll>
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define llmax LLONG_MAX/2
#define llmin -LLONG_MAX/2
using namespace std;
#define mn 100100
#define pa pair<ll, ll>
#define ld long double 
ll a[mn], b[mn], srt[mn];
ll mm=2000200;
int main(){
    ll n, k;cin>> n >> k;
    loop(i, 0, n) cin >> a[i];
    loop(i, 0, n) cin >> b[i];
    loop(i, 0, n) srt[i+1]=b[i]-a[i];
    sort(srt+1, srt+n+1);
    ll j=0, ans=llmax, l=0, r=k, cur=n-r;
    loop(i, 1, n-k+1) cur+=srt[i]+mm;
    loop(i, -mm, mm){
        while(j<n and srt[j+1]<i)j++;
        cur-=n-j-j+l-r;
        while(l+1<=j and r>0 and i-srt[l+1]>=srt[n+1-r]-i) cur-=srt[n+1-r]+srt[l+1]-2 * i,l++, r--;
        // cout << i << " "<<cur <<" "<<l << " "<<r<<endl;
        ans=min(ans, cur);
    }
    cout << ans <<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 364 KB Output is correct
2 Correct 10 ms 364 KB Output is correct
3 Correct 10 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 4072 KB Output is correct
2 Correct 85 ms 4196 KB Output is correct
3 Correct 87 ms 4072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 4068 KB Output is correct
2 Correct 90 ms 4196 KB Output is correct
3 Correct 84 ms 4196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 4116 KB Output is correct
2 Correct 85 ms 4068 KB Output is correct
3 Correct 83 ms 4196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 61 ms 3424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 89 ms 4068 KB Output is correct
2 Incorrect 96 ms 4200 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 93 ms 4060 KB Output is correct
2 Correct 86 ms 4140 KB Output is correct
3 Incorrect 87 ms 4068 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 90 ms 4100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 89 ms 4072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 87 ms 4068 KB Output is correct
2 Correct 85 ms 4224 KB Output is correct
3 Correct 92 ms 4068 KB Output is correct