Submission #703925

# Submission time Handle Problem Language Result Execution time Memory
703925 2023-03-01T01:56:01 Z chenyan Simfonija (COCI19_simfonija) C++17
44 / 110
34 ms 4048 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]=a[i]+p[i-1];
	int l=1,r=1;
	int ans=1e18;
	for(i=1;i<=n;i++){
		while(r<n&&a[r+1]<=a[i]+k)r++;
		while(a[l]<a[i])l++;
		ans=min(a[i]*(l-1)-p[l-1]+(p[n]-p[r])-(a[i]+k)*(n-r),ans);
	}
	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 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 3984 KB Output is correct
2 Correct 23 ms 4040 KB Output is correct
3 Correct 21 ms 3996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 3916 KB Output is correct
2 Correct 25 ms 4012 KB Output is correct
3 Correct 21 ms 4048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 3876 KB Output is correct
2 Correct 23 ms 4024 KB Output is correct
3 Correct 21 ms 4044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 3288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 3876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 3892 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 3916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 3916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 3892 KB Output isn't correct
2 Halted 0 ms 0 KB -