Submission #703927

# Submission time Handle Problem Language Result Execution time Memory
703927 2023-03-01T02:51:51 Z chenyan Simfonija (COCI19_simfonija) C++17
77 / 110
32 ms 4092 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];
	sort(a+1,a+n+1);
	for(i=1;i<=n;i++)p[i]=p[i-1]+a[i];
	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 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 2672 KB Output is correct
2 Correct 23 ms 2632 KB Output is correct
3 Correct 20 ms 2704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 2636 KB Output is correct
2 Correct 23 ms 2536 KB Output is correct
3 Correct 22 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 2600 KB Output is correct
2 Correct 25 ms 2600 KB Output is correct
3 Correct 20 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 2628 KB Output is correct
2 Correct 21 ms 4028 KB Output is correct
3 Correct 21 ms 4016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2624 KB Output is correct
2 Correct 25 ms 4044 KB Output is correct
3 Correct 26 ms 4084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 2592 KB Output is correct
2 Correct 32 ms 4016 KB Output is correct
3 Incorrect 25 ms 4016 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 2668 KB Output is correct
2 Incorrect 27 ms 4092 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2672 KB Output is correct
2 Correct 25 ms 4052 KB Output is correct
3 Correct 25 ms 4084 KB Output is correct