Iamtui1010

doll.cpp

Jan 10th, 2022
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<algorithm>
  4. #include<vector>
  5. //#include<conio.h>
  6.  
  7. #define long long long
  8. #define nln '\n'
  9.  
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14.     // Input
  15.     cin.tie(0)->sync_with_stdio(0);
  16.     cout.tie(0)->sync_with_stdio(0);
  17.     //freopen("doll.inp", "r", stdin);
  18.     long n, k;
  19.     cin >> n >> k;
  20.     vector<long> a(n);
  21.     for (auto &i : a)
  22.     {
  23.         cin >> i;
  24.         i *= -1;
  25.     }
  26.     sort(a.begin(), a.end());
  27.     // Process
  28.     long ans = 0;
  29.     while (!a.empty())
  30.     {
  31.         ans += a[0]*(-1);
  32.         long pst = 0;
  33.         while (pst != (long)a.size())
  34.         {
  35.             long cor = a[pst];
  36.             a.erase(a.begin()+pst);
  37.             pst = (long)(lower_bound(a.begin(), a.end(), cor+k)-a.begin());
  38.         }
  39.     }
  40.     cout << ans << nln;
  41.     return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment