답안 #676435

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
676435 2022-12-30T22:17:00 Z Essa2006 Simfonija (COCI19_simfonija) C++11
110 / 110
33 ms 1108 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define endl '\n'
#define FF first
#define SS second
#define all(a) Pre, Pre+n
#define mod (int)(1000000007)
const int inf = 1e18;
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n, k;
    cin>>n>>k;
    int Pre[n];
    for(int i=0;i<n;i++){
        cin>>Pre[i];
    }
    for(int i=0, a;i<n;i++){
        cin>>a;
        Pre[i]-=a;
    }
    sort(all(Pre));
    int ans=inf;
    for(int i=1;i<n;i++)
        Pre[i]+=Pre[i-1];
    for(int i=0, r=n-k-1, md=(n-k)/2;r<n;i++, r++, md++){
        int val=Pre[md]-(md?Pre[md-1]:0);
        int sum=(md-i+1)*val-(Pre[md]-(i?Pre[i-1]:0))+(r+1?Pre[r]:0)-Pre[md]-val*(r-(md+1)+1);
        ans=min(ans, sum);
    }
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 980 KB Output is correct
2 Correct 24 ms 1096 KB Output is correct
3 Correct 26 ms 1096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 980 KB Output is correct
2 Correct 22 ms 980 KB Output is correct
3 Correct 19 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 1080 KB Output is correct
2 Correct 24 ms 1108 KB Output is correct
3 Correct 20 ms 1092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 980 KB Output is correct
2 Correct 19 ms 980 KB Output is correct
3 Correct 22 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 1092 KB Output is correct
2 Correct 26 ms 1092 KB Output is correct
3 Correct 24 ms 1096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 980 KB Output is correct
2 Correct 25 ms 980 KB Output is correct
3 Correct 22 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 980 KB Output is correct
2 Correct 19 ms 980 KB Output is correct
3 Correct 27 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 980 KB Output is correct
2 Correct 27 ms 1088 KB Output is correct
3 Correct 26 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 1100 KB Output is correct
2 Correct 20 ms 980 KB Output is correct
3 Correct 28 ms 980 KB Output is correct