Untitled
unknown
c_cpp
a month ago
884 B
0
Indexable
Never
#include <bits/stdc++.h> using namespace std ; #include <algorithm> #define int long long void solve () { int n,k;cin>>n>>k; int a[n],b[n]; int idx1=0,idx2=0, for(int i = 0; i<n;i++) cin>>a[i]; for(int i = 0; i<n;i++)cin>>b[i]; int m1,m2; m1 = a[(n/2)-1];m2 = a[n/2]; for(int i = 0; i<n;i++) if(b[i] == 1) a[i] += k; int x = a[0],y=a[n-1]; for(int i = 0; i<n-2;i++) if(x < a[i]) { x = a[i]; idx1 =i; } for(int i = n/2 ; i < n; i++) if(y < a[i]) { y = a[i]; idx2 = i; } int max1 = m1+y; int max2 =m2+x; if(b[(n/2)-1] ==1 &&b[idx2] ==1) max2-= k; if(b[(n/2)] == 1 && b[idx1] ==1) max1 -= k; cout << max(max1,max2) << endl; } signed main () { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); // cin>>t; // while(t--) // { solve(); // } return 0; }
Leave a Comment