[Help] Problem A [Div 2 - #672] .C++ code gives AC, Java code gives WA.
Разница между en1 и en2, 179 символ(ов) изменены
As the title says I need some help to find some test cases where my solution fails for the problem [Cubes Sorting](https://codeforces.com/contest/1420/problem/A).↵
My logic is simple, I first sort the array in decreasing order, then check if two elements are the same in the array.↵
Then i check if the original array is in strictly decreasing order. If either the original array is not sorted in decreasing order or if there are two(or more) elements with the same value I print out YES else No.↵
My Java Code:- ↵

<spoiler summary="Spoiler">↵
~~~~~↵
int n = in.nextInt();↵
int[] a = in.readArray(n);↵
ArrayList<Integer> sorted = new ArrayList<Integer>();↵
for(int i:a) sorted.add(i);↵
Collections.sort(sorted,Collections.reverseOrder());↵
boolean isPoss = false;↵
boolean isSame = false;↵
for(int i=1;i<n;i++)↵
if(sorted.get(i)==sorted.get(i-1))isSame = true;↵
for(int i=0;i<n;i++) ↵
if(a[i]!=sorted.get(i))isPoss = true;↵
if(isPoss||isSame) out.println("YES");↵
else { ↵
out.println("NO");↵
}↵

~~~~~↵


</spoiler>↵

The logic seems right to me but it is still giving WA.Link to WA Submission [submission:93757010].↵
Any help is appreciated.


Update: Seems like the same code in C++ gives AC [submission:93846515]. ↵
Is there some error in my implementation of the solution?

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский kalzor 2020-09-26 11:09:30 8
en2 Английский kalzor 2020-09-26 10:37:44 179
en1 Английский kalzor 2020-09-26 08:30:05 1181 Initial revision (published)