CM1902-Editorial

PROBLEM LINK:

Practice
Contest

Author: Neeraj
Tester: Sumit
Editorialist: Manish

DIFFICULTY:

EASY.

PREREQUISITES:

Math, Time and Space Complexity;

PROBLEM:

You are given an array A of N elements You have performed Q queries in it in each query, you select an index I (0. based ) and perform the following operation For j = I + 1 to N-1;

If A[j] < A[I];

A[j] = 0

You are required to print the version of array A after all the Q queries are Proceed.

SOLUTIONS:

Setter's Solution

indent whole code by 4 spaces

Tester's Solution

indent whole code by 4 spaces

Editorialist's Solution
#include<bits/stdc++.h>

using namespace std;

int main(){
int t;
cin>>t;
while(t–){
int n,q;
cin>>n>>q;
int *arr = new int[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
int *qrr = new int[q];
bool *valid = new booln;
for(int i=0;i<q;i++){
cin>>qrr[i];
valid[qrr[i]] = true;
}

	int max=0;
	for(int i=0;i<n;i++){
		if(arr[i]<max)
			arr[i]=0;
		else if(valid[i])
 			max=arr[i];
	}

	for(int i=0;i<n;i++){
		cout<<arr[i]<<" ";
	}
	cout<<endl;
}
return 0;

}