Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Solve() {// << The Art of تخاذل >>
- ll n;cin>>n;
- vector<ll>v(n),copy(n+1); cin>>v;
- for(int i=0;i<n;i++){
- ll k=v[i];
- if(v[i]>0){
- copy[i]+=1;
- copy[i+k]-=1;
- }
- }
- partial_sum(all(copy),copy.begin());
- //**************
- int start = 0, end = 0, maxLength = 1;
- for (int i = 0; i < n; i++) {
- for (int j = i + 1; j < n; j++) {
- bool allEqual = true;
- for (int k = i; k < j; k++) {
- if (copy[k] != copy[k+1]) {
- allEqual = false;
- break;
- }
- }
- if (allEqual && j - i + 1 > maxLength) {
- start = i;
- end = j;
- maxLength = j - i + 1;
- }
- }
- }
- if(copy[start]==0) cout<<-1<<endl;
- /* cout << "Longest equal subarray: ";
- for (int i = start; i <= end; i++) {
- cout << copy[i] << " ";
- }
- cout << endl;*/
- else cout<<end-start+1<<" "<<start+1<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement