Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void updatedArr(vector<long int>&arr, int low, int high)
  5. {
  6. arr[low]++;
  7. if (high != arr.size() - 1)
  8. arr[high+1]--;
  9. }
  10.  
  11. int main()
  12. {
  13. ios_base::sync_with_stdio(false);
  14. cin.tie(NULL);
  15.  
  16. int T, N;
  17. cin >> T;
  18. while(T > 0)
  19. {
  20. cin >> N;
  21. vector<long int>CP, CL(N, 0), health; // cavePower, caveLvl, caveHlth
  22. for(long int x, i=0; i < N; i++) {
  23. cin >> x;
  24. CP.push_back(x);
  25. }
  26.  
  27. for(long int x, i=0; i < N; i++) {
  28. cin >> x;
  29. health.push_back(x);
  30.  
  31. // getting caves associated with current i and calmping values
  32. int low = i - CP[i] < 0 ? 0 : i-CP[i];
  33. int high = i + CP[i] > N-1 ? N-1 : i+CP[i];
  34.  
  35. // increasing level of caves
  36. updatedArr(CL, low, high);
  37. }
  38.  
  39. for(int i=1;i < CL.size(); i++)
  40. CL[i] += CL[i-1];
  41.  
  42. sort(health.begin(), health.end());
  43. sort(CL.begin(), CL.end());
  44.  
  45. CL == health ? cout << "YES\n" : cout << "NO\n";
  46. T--;
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement