Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define vi vector<int>
  6. #define ll long long
  7. #define pb push_back
  8. #define mp make_pair
  9. #define ii pair<int,int>
  10.  
  11. #define NDEBUG
  12. #include <assert.h>
  13.  
  14.  
  15. int main(){
  16.     int n,k1,k2;
  17.     int aux;
  18.     priority_queue<ii> diferencas;
  19.     vector<int> A,B;
  20.  
  21.     scanf("%d %d %d",&n,&k1,&k2);
  22.     for (int i = 0; i < n; ++i)
  23.     {
  24.         scanf("%d",&aux);
  25.         A.pb(aux);
  26.     }
  27.  
  28.     for (int i = 0; i < n; ++i)
  29.     {
  30.         scanf("%d",&aux);
  31.         B.pb(aux);
  32.         if(A[i] > aux){
  33.           diferencas.push(mp((A[i] - aux),i));
  34.         }else{
  35.           diferencas.push(mp((aux - A[i]),i));
  36.         }
  37.     }
  38.  
  39.     ii base = diferencas.top();
  40.     ii it;
  41.     int m = k1+k2;
  42.  
  43.    
  44.     int j = 0;
  45.    
  46.     while(m > 0)
  47.     {
  48.         it = diferencas.top();
  49.         if(it.first >= base.first){
  50.             if (A[j] > B[j])
  51.             {
  52.                 it.first--;
  53.             }else{
  54.                 if ((A[j] - B[j]) < 0)
  55.                 {
  56.                   it.first--;  
  57.                 }else{
  58.                   it.first++;
  59.                 }
  60.             }
  61.             m--;
  62.             diferencas.push(it);
  63.         }
  64.         diferencas.pop();
  65.         base = diferencas.top();
  66.         //printf("nova base %d\n", base.first);
  67.     }
  68.  
  69.     m = diferencas.size();
  70.     int sum = 0;
  71.  
  72.     for (int i = 0; i < m; ++i)
  73.     {
  74.         it = diferencas.top();
  75.         sum += (it.first)*(it.first);
  76.         diferencas.pop();
  77.     }
  78.  
  79.     printf("%d\n", sum);
  80.    
  81.  
  82.     return 0;
  83. }
  84.  
  85.  
  86. /*
  87. compilar
  88. g++ arquivo.cpp -std=c++11 -o executavel
  89. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement