Submission #318856

# Submission time Handle Problem Language Result Execution time Memory
318856 2020-11-03T10:27:56 Z neki Simfonija (COCI19_simfonija) C++14
0 / 110
86 ms 4464 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=10;
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 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 80 ms 4464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 79 ms 4156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 82 ms 4072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 53 ms 3428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 4060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 72 ms 4096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 80 ms 4068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 86 ms 4176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 4140 KB Output isn't correct
2 Halted 0 ms 0 KB -