Advertisement
amine99

Untitled

Apr 7th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 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 reloop(i,e,b) for(auto i=e;i>=b;i--)
  6. #define loop(i,b,e) for(auto i=b;i<=e;i++)
  7. #define ALL(x) x.begin(),x.end()
  8. #define F first
  9. #define S second
  10. typedef long long LL;
  11. typedef vector<int> VI;
  12. typedef long long LL;
  13. typedef vector<int> VI;
  14.  
  15. bool compare(const std::pair<int, int>&i, const std::pair<int, int>&j) {
  16.     return abs(i.first-i.second) > abs(j.first - j.second);
  17. }
  18. pair<int,int> t[1001];
  19. int n,k1,k2;
  20.  
  21. int main() {_
  22.    cin >> n >> k1 >> k2;
  23.    loop(i,0,n-1)
  24.       cin >> t[i].F;
  25.    loop(i,0,n-1)
  26.       cin >> t[i].S;
  27.    sort(t,t+n,compare);
  28.    while(k1 > 0) {
  29.       sort(t,t+n,compare);
  30.       if(t[0].F >= t[0].S)
  31.          t[0].F--;
  32.       else if(t[0].F < t[0].S)
  33.          t[0].F++;
  34.       k1--;
  35.    }
  36.    sort(t,t+n,compare);
  37.    while(k2 > 0) {
  38.       sort(t,t+n,compare);
  39.       if(t[0].S >= t[0].F)
  40.          t[0].S--;
  41.       else if(t[0].S < t[0].F)
  42.          t[0].S++;
  43.       k2--;
  44.    }
  45.    LL ans=0;
  46.    loop(i,0,n-1)
  47.       ans += (LL)(t[i].F-t[i].S)*(LL)(t[i].F-t[i].S);
  48.    cout << ans;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement