Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* c782 */
- /* AC (0.3s, 17.2MB) */
- #pragma warning( disable : 4996 )
- #include <cstdio>
- #include <cstring>
- #include <cstdint>
- #include <cmath>
- #include <algorithm>
- #include <tuple>
- #define ios_jazz ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
- using namespace std;
- constexpr int Dir4[4][2] = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} };
- constexpr int Dir8[8][2] = { {-1, -1}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 1} };
- constexpr double EPS = 1e-9;
- const double PI = acos(-1);
- using int16 = short;
- using uint16 = unsigned short;
- using uint = unsigned int;
- using int64 = long long;
- using uint64 = unsigned long long;
- using pii = pair<int, int>;
- /* fast power */
- auto pow_fast_2 = [](int64 b) -> int64 { return 1 << b; };
- template <typename T>
- T pow_fast(T x, int64 b) noexcept
- {
- T tmp = 1;
- while (b)
- {
- if (b & 0x1) tmp = x * tmp;
- x = x * x;
- b >>= 1;
- }
- return tmp;
- }
- /* main code */
- constexpr int MAXN = 2000000;
- int t, n, k, arr[MAXN + 1], l, r;
- int64 ans, wi[MAXN + 1]{};
- int main()
- {
- scanf("%d", &t);
- while (t-- && scanf("%d %d", &n, &k))
- {
- ans = 0, l = n - 1, r = n;
- for (int i = 1; i <= n; ++i) scanf("%d", arr + i);
- for (int i = 1; i <= n; wi[i] += wi[i - 1], ++i) scanf("%lld", wi + i);
- while (l && (arr[r] - arr[l]) <= k)
- --l;
- while(l)
- {
- ans += (wi[r] - wi[r - 1]) * wi[l];
- --r;
- while (l && (arr[r] - arr[l]) <= k)
- --l;
- }
- printf("%lld\n", ans);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement