Advertisement
SuitNdtie

Archery

Oct 8th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll;
  5.  
  6. struct elem{
  7.     ll high;
  8.     ll pos;
  9.     bool operator < (const elem &rhs)const
  10.     {
  11.         return pos < rhs.pos;
  12.     }
  13. };
  14.  
  15. int main()
  16. {
  17.     //freopen("input.txt","r",stdin);
  18.     int n;
  19.     scanf("%d",&n);
  20.     elem arr[n];
  21.     ll minhigh = 1e9+10;
  22.     ll sumback = 0;
  23.     ll sumposfront = 0;
  24.     ll sumhighfront = 0;
  25.     for(int i = 0 ; i < n ; i ++){
  26.         scanf("%lld",&arr[i].high);
  27.         minhigh = min(minhigh,arr[i].high);
  28.     }
  29.     for(int i = 0 ; i < n ; i ++){
  30.         scanf("%lld",&arr[i].pos);
  31.         sumback += arr[i].pos;
  32.     }
  33.     sort(arr,arr+n);
  34.    
  35.     ll mina = 1e18,mini;
  36.     for(int i = 0 ; i < n ; i++){
  37.         ll p = arr[i].pos;
  38.         sumback -= p;
  39.         if(p > minhigh)break;
  40.         ll cost = (sumback - (n-i-1)*p) + (sumposfront+sumhighfront-(i*p));
  41.         if(cost < mina){
  42.             mina = cost;
  43.             mini = p;
  44.         }
  45.        
  46.         sumposfront += arr[i].pos;
  47.         sumhighfront += arr[i].high;
  48.     }
  49.     printf("%lld %lld",mini,mina);
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement