Advertisement
amine99

Untitled

Apr 7th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  5. #define itloop(it,x) for(auto it=x.begin();it!=x.end();it++)
  6. #define reloop(i,e,b) for(auto i=e;i>=b;i--)
  7. #define loop(i,b,e) for(auto i=b;i<=e;i++)
  8. #define ALL(x) x.begin(),x.end()
  9. #define SZ(x) x.size()
  10. #define PB push_back
  11. #define MP make_pair
  12. #define F first
  13. #define S second
  14. typedef long long LL;
  15. typedef vector<int> VI;
  16. typedef long long LL;
  17. typedef vector<int> VI;
  18.  
  19. bool compare(const std::pair<int, int>&i, const std::pair<int, int>&j) {
  20.     return abs(i.first-i.second) > abs(j.first - j.second);
  21. }
  22. pair<int,int> t[1001];
  23. int n,k1,k2;
  24.  
  25. int main() {_
  26.    cin >> n >> k1 >> k2;
  27.    loop(i,0,n-1)
  28.       cin >> t[i].F;
  29.    loop(i,0,n-1)
  30.       cin >> t[i].S;
  31.    sort(t,t+n,compare);
  32.    while(k1 > 0) {
  33.       sort(t,t+n,compare);
  34.       if(t[0].F > t[0].S)
  35.          t[0].F--;
  36.       else if(t[0].F < t[0].S)
  37.          t[0].F++;
  38.       else
  39.          break;
  40.       k1--;
  41.    }
  42.    sort(t,t+n,compare);
  43.    while(k2 > 0) {
  44.       sort(t,t+n,compare);
  45.       if(t[0].S > t[0].F)
  46.          t[0].S--;
  47.       else if(t[0].S < t[0].F)
  48.          t[0].S++;
  49.       else
  50.          break;
  51.       k2--;
  52.    }
  53.    LL ans=0;
  54.    loop(i,0,n-1)
  55.       ans += (LL)(t[i].F-t[i].S)*(LL)(t[i].F-t[i].S);
  56.    cout << ans;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement