Submission #318884

# Submission time Handle Problem Language Result Execution time Memory
318884 2020-11-03T12:04:11 Z neki Simfonija (COCI19_simfonija) C++14
55 / 110
98 ms 4356 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];
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=0;
    loop(i, 1, n-k+1) cur+=srt[i]-srt[1];
    loop(j, 0, n){
        ll i=srt[j+1];
        if(j!=0) cur-=(n-j-j+l-r) * (srt[j+1]-srt[j]);
        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 <<" "<<j<< " "<<l << " "<<r<<endl;
        ans=min(ans, cur);
    }
    cout << ans <<endl;
}

Compilation message

simfonija.cpp: In function 'int main()':
simfonija.cpp:29:8: warning: unused variable 'j' [-Wunused-variable]
   29 |     ll j=0, ans=llmax, l=0, r=k, cur=0;
      |        ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 396 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 4088 KB Output is correct
2 Correct 98 ms 4016 KB Output is correct
3 Correct 74 ms 4068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 4096 KB Output is correct
2 Correct 91 ms 4164 KB Output is correct
3 Correct 73 ms 4068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 4228 KB Output is correct
2 Correct 78 ms 4196 KB Output is correct
3 Correct 79 ms 4068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 3428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 85 ms 4020 KB Output is correct
2 Incorrect 82 ms 4068 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 71 ms 4068 KB Output is correct
2 Incorrect 78 ms 4068 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 82 ms 4172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 4068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 75 ms 4196 KB Output is correct
2 Correct 74 ms 4068 KB Output is correct
3 Correct 80 ms 4356 KB Output is correct