Advertisement
Emiliatan

c782

Jul 22nd, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. /* c782              */
  2. /* AC (0.3s, 17.2MB) */
  3. #pragma warning( disable : 4996 )
  4. #include <cstdio>
  5. #include <cstring>
  6. #include <cstdint>
  7. #include <cmath>
  8. #include <algorithm>
  9. #include <tuple>
  10. #define ios_jazz ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
  11.  
  12. using namespace std;
  13.  
  14. constexpr int Dir4[4][2] = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} };
  15. constexpr int Dir8[8][2] = { {-1, -1}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 1} };
  16. constexpr double EPS = 1e-9;
  17. const double PI = acos(-1);
  18.  
  19. using int16 = short;
  20. using uint16 = unsigned short;
  21. using uint = unsigned int;
  22. using int64 = long long;
  23. using uint64 = unsigned long long;
  24. using pii = pair<int, int>;
  25.  
  26. /* fast power */
  27. auto pow_fast_2 = [](int64 b) -> int64 { return 1 << b; };
  28.  
  29. template <typename T>
  30. T pow_fast(T x, int64 b) noexcept
  31. {
  32.     T tmp = 1;
  33.     while (b)
  34.     {
  35.         if (b & 0x1) tmp = x * tmp;
  36.         x = x * x;
  37.         b >>= 1;
  38.     }
  39.     return tmp;
  40. }
  41.  
  42. /* main code */
  43. constexpr int MAXN = 2000000;
  44. int t, n, k, arr[MAXN + 1], l, r;
  45. int64 ans, wi[MAXN + 1]{};
  46. int main()
  47. {
  48.     scanf("%d", &t);
  49.     while (t-- && scanf("%d %d", &n, &k))
  50.     {
  51.         ans = 0, l = n - 1, r = n;
  52.         for (int i = 1; i <= n; ++i) scanf("%d", arr + i);
  53.         for (int i = 1; i <= n; wi[i] += wi[i - 1], ++i) scanf("%lld", wi + i);
  54.  
  55.         while (l && (arr[r] - arr[l]) <= k)
  56.             --l;
  57.         while(l)
  58.         {
  59.             ans += (wi[r] - wi[r - 1]) * wi[l];
  60.             --r;
  61.             while (l && (arr[r] - arr[l]) <= k)
  62.                 --l;
  63.         }
  64.         printf("%lld\n", ans);
  65.     }
  66.  
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement