My issue
When I reverse sort it (like in the code below), and traverse from the start, it gives WA, yet if I sort it in ascending and traverse from back, it passes the test cases. Why is it so, is it some bug?
My code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sorti(a) sort(a.begin(), a.end())
#define sortr(a) sort(a.begin(), a.end(), greater<int>())
#define print(v) for(auto &i:v) cout<<i<<" "; cout<<endl;
#define forn(i, n) for (int i = 0; i < int(n); i++)
//***************************************************************************************
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
int t; cin>>t;
while(t--)
{
ll n; cin>>n;
vector<ll> a(n);
forn(i, n)
cin>>a[i];
sortr(a);
// print(a);
ll ans=1, X=a[0];
for(int i=1; i<n; i++)
{
if(a[i]<=X)
{
X=X^a[i];
}
else
{
ans++;
X=a[0];
}
}
cout<<ans<<endl;
}
return 0;
}
Problem Link: BOX95 Problem - CodeChef