You are viewing a single comment's thread. Return to all comments →
Please Comment a short test case to prove my solution wrong.
public static void main(String[] args) {
long j,count=0l,k,sum=0l,max=0l; int i,n,max_pos=-1; boolean move=false; Scanner s=new Scanner(System.in); n=s.nextInt(); k=s.nextInt(); long a[]=new long[n]; long a2[]=new long[n]; for(i=0;i<n;i++) { a[i]=s.nextLong(); } for(i=0;i<n;i++) { a2[i]=0; } //input over //processing start for(j=0;j<n;j++) {max=0; for(i=0;i<n;i++) { if(max<a[i]) {max=a[i]; max_pos=i; } } //condn to move count=0; for(i=max_pos-1;i>=0;i--) { if(a2[i]==0 || count>k+1) break; else ++count; } if(count<k+1) { for(i=max_pos+1;i<n;i++) { if(a2[i]==0 || count>k+1) break; else ++count; } } if(count<k) move=true; if(move==true) { a2[max_pos]=a[max_pos]; } a[max_pos]=0; move=false; } //output start for(i=0;i<n;i++) { sum+=a2[i]; } System.out.print(sum); }
Seems like cookies are disabled on this browser, please enable them to open this website
Billboards
You are viewing a single comment's thread. Return to all comments →
Please Comment a short test case to prove my solution wrong.
public static void main(String[] args) {