Advertisement
amine99

Untitled

Apr 7th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 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.  
  32.    while(k1 > 0 || k2 > 0) {
  33.       sort(t,t+n,compare);
  34.      
  35.       if(k1 > 0 && k2 > 0) {
  36.          if(t[0].F > t[0].S)
  37.             t[0].F--,t[0].S++;
  38.          else if(t[0].F < t[0].S)
  39.             t[0].F++,t[0].S--;
  40.          else {
  41.             k1 = 0;
  42.             k2 = 0;
  43.          }
  44.          k1--;
  45.          k2--;
  46.       }
  47.      
  48.       else if(k1 > 0 && k2 == 0) {
  49.          if(t[0].F > t[0].S)
  50.             t[0].F--;
  51.          else if(t[0].F < t[0].S)
  52.             t[0].F++;
  53.          else {
  54.             k1 = 0;
  55.             k2 = 0;
  56.          }
  57.          k1--;
  58.       }
  59.      
  60.       else if(k1 == 0 && k2 > 0) {
  61.          if(t[0].S > t[0].F)
  62.             t[0].S--;
  63.          else if(t[0].S < t[0].F)
  64.             t[0].S++;
  65.          else {
  66.             k1 = 0;
  67.             k2 = 0;
  68.          }
  69.          k2--;
  70.       }
  71.    }
  72.    
  73.    
  74.   /* loop(i,0,n-1)
  75.       printf("%d ",t[i].F);
  76.    printf("\n");
  77.    loop(i,0,n-1)
  78.       printf("%d ",t[i].S);*/
  79.  
  80.    LL ans=0;
  81.    loop(i,0,n-1)
  82.       ans += (LL)abs(t[i].F-t[i].S)*(LL)abs(t[i].F-t[i].S);
  83.    cout << ans;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement