Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- void updatedArr(vector<long int>&arr, int low, int high)
- {
- arr[low]++;
- if (high != arr.size() - 1)
- arr[high+1]--;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int T, N;
- cin >> T;
- while(T > 0)
- {
- cin >> N;
- vector<long int>CP, CL(N, 0), health; // cavePower, caveLvl, caveHlth
- for(long int x, i=0; i < N; i++) {
- cin >> x;
- CP.push_back(x);
- }
- for(long int x, i=0; i < N; i++) {
- cin >> x;
- health.push_back(x);
- // getting caves associated with current i and calmping values
- int low = i - CP[i] < 0 ? 0 : i-CP[i];
- int high = i + CP[i] > N-1 ? N-1 : i+CP[i];
- // increasing level of caves
- updatedArr(CL, low, high);
- }
- for(int i=1;i < CL.size(); i++)
- CL[i] += CL[i-1];
- sort(health.begin(), health.end());
- sort(CL.begin(), CL.end());
- CL == health ? cout << "YES\n" : cout << "NO\n";
- T--;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement