SHARE
TWEET

Untitled

a guest Feb 17th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <math.h>
  3. #include <algorithm>
  4.  
  5. using  namespace std;
  6.  
  7. int len[10];
  8.  
  9.  
  10. int resi(int n, int b, int e, int k) {
  11.     if (k == 0) {
  12.         return pow(e, 2) - pow(b, 2);
  13.     }
  14.     int a = INT_MAX, c = INT_MAX;
  15.     if (len[e] <= k) {
  16.         int temp2 = e;
  17.         temp2--;
  18.         while (len[temp2] == 0) {
  19.             temp2--;
  20.         }
  21.         a = resi( n, b, temp2, k - len[e]);
  22.     }
  23.     if (len[b] <= k) {
  24.         int temp2 = b;
  25.         temp2++;
  26.         while (len[temp2] == 0) {
  27.             temp2++;
  28.         }
  29.         c = resi( n, temp2, e, k - len[b]);
  30.     }
  31.     if (a == INT_MAX && c == INT_MAX) {
  32.         k = 0;
  33.         return resi( n, b, e, 0);
  34.     }
  35.  
  36.     return min(a, c);
  37. }
  38.  
  39. int main() {
  40.     int  n, k;
  41.     cin >> n >> k;
  42.     for (int i = 0; i < 10; i++) {
  43.         len[i] = 0;
  44.     }
  45.     for (int i = 0; i < n; i++) {
  46.         int temp;
  47.         cin >> temp;
  48.         len[temp]++;
  49.     }
  50.     int mali, veliki;
  51.     for (int i = 0; i < 10; i++) {
  52.         if (len[i] != 0) {
  53.             mali = i;
  54.             break;
  55.         }
  56.     }
  57.     for (int i = 9; i >= 0; i--) {
  58.         if (len[i] != 0) {
  59.             veliki = i;
  60.             break;
  61.         }
  62.     }
  63.     int maxlen = len[0];
  64.     for (int i = 1; i < 10; i++) {
  65.         if (maxlen < len[i]) {
  66.             maxlen = len[i];
  67.         }
  68.     }
  69.     if (n - maxlen <= k) {
  70.         cout << 0;
  71.     }
  72.     else {
  73.         cout << resi(n, mali, veliki, k);
  74.     }
  75. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top