Submission #703926

# Submission time Handle Problem Language Result Execution time Memory
703926 2023-03-01T02:35:31 Z chenyan Simfonija (COCI19_simfonija) C++17
0 / 110
28 ms 2676 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb emplace_back
#define N 100010
int dp[N],a[N],b[N],p[N];
vector<int>v;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m,i,k,j;
	cin>>n>>k;
	for(i=1;i<=n;i++)cin>>a[i];
	for(i=1;i<=n;i++)cin>>b[i];
	for(i=1;i<=n;i++)a[i]=b[i]-a[i],p[i]=a[i]+p[i-1];
	sort(a+1,a+n+1);
	int l=0,r=n-k,ans=1e18;
	for(i=1;i<=n;i++){
		while(l<i&&r<n&&a[r]-a[i]<a[i]-a[l+1])l++,r++;
		ans=min(ans,(p[r]-p[i])-a[i]*(r-i)+a[i]*(i-l)-(p[i]-p[l]));
	}
	cout<<ans<<'\n';
}

Compilation message

simfonija.cpp: In function 'int main()':
simfonija.cpp:15:8: warning: unused variable 'm' [-Wunused-variable]
   15 |  int n,m,i,k,j;
      |        ^
simfonija.cpp:15:14: warning: unused variable 'j' [-Wunused-variable]
   15 |  int n,m,i,k,j;
      |              ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 2676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 2608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 2564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 2588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 2584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 2576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 2656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -