Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define x first
- #define y second
- #define mp make_pair
- #define ll long long
- using namespace std;
- const int sz = 5e5;
- typedef pair<int,int> ii;
- ii box[sz+5];
- ll qs_height[sz+5],qs_hole[sz+5];
- int main()
- {
- int n;
- cin >> n;
- for(int i=1;i<=n;i++) cin >> box[i].y;
- for(int i=1;i<=n;i++) cin >> box[i].x;
- sort(box+1,box+n+1);
- for(int i=1;i<=n;i++) {
- qs_height[i]=qs_height[i-1]+box[i].y;
- qs_hole[i]=qs_hole[i-1]+box[i].x;
- }
- pair<long long,int> ans=mp((long long) 1e18,(int) 1e9+1);
- for(int i=1;i<=n;i++) {
- int x = box[i].x;
- auto it = lower_bound(box+1,box+n+1,mp(x,0));
- int po=it-box;
- long long cnt = (qs_height[po-1]+qs_hole[po-1]-((long long) x*po-x));
- long long cnt2 = qs_hole[n]-qs_hole[po]-((long long) x*(n-po));
- ans=min(ans,mp(cnt+cnt2,x));
- }
- cout << ans.y << " " << ans.x;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement