generated from OPCODE-Open-Spring-Fest/template
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3bf3dc3
commit 903f8de
Showing
1 changed file
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,38 @@ | ||
// Write Your Code Here | ||
// Write Your Code Here | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL); | ||
typedef long long int ll; | ||
|
||
int main() | ||
{ | ||
fast; | ||
int T; cin >> T; | ||
while(T--) | ||
{ | ||
ll n,k; cin >> n >> k; | ||
ll a[n]; | ||
for(ll i=0; i<n; i++){cin >> a[i];} | ||
vector<ll>count(n,0); | ||
ll flag = 0; | ||
|
||
ll start = 0; ll end = n-1; | ||
for(ll i=0; i<k; i++) | ||
{ | ||
if(count[end] != 0){break;} | ||
if(a[end]>n){flag++; break;} | ||
count[end]++; | ||
ll x = a[end]; | ||
|
||
start = (start-(x%n)); | ||
end = (end-(x%n)); | ||
if(end < 0){end = end+n;} | ||
if(start < 0){start = start+n;} | ||
|
||
ll y = (start+x-1)%n; | ||
if(a[y] != x){flag++; break;} | ||
} | ||
if(flag == 0){cout << "YES" << endl;} | ||
else{cout << "NO" << endl;} | ||
} | ||
} |