PROSUM - Editorial

still getting WA with this :-

int main()
{
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
VI arr;
REP(i,n)
{
int a;
cin>>a;
arr.pb(a);
}
int twoes=0,others=0;
REP(i,n)
{
if(arr[i] == 2)
twoes++;
if(arr[i] > 2)
others++;
}
ll ans = twoesothers1LL;
ans += (1LLothers(others-1))/2;
cout<<ans<<endl;
}
}

Can you provide a code without defines, or the full code with defines you used? I am not able to get “ll ans = twoesothers1LL; ans += (1LLothers(others-1))/2” Is multiplication going on here? You should store twoes and others as long long int, as overflow will occur. (Try changing data type of twoes and others to long long int)

Am I missing something??

import java.util.;
import java.io.
;
class Sol
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st,st1,st2;
String s2=br.readLine();
st2=new StringTokenizer(s2);
int t=Integer.parseInt(st2.nextToken());
while(t-- > 0)
{
String s1=br.readLine();
st1=new StringTokenizer(s1);
int n=Integer.parseInt(st1.nextToken());
int GT2=0;
int twos=0;
String s=br.readLine();
st=new StringTokenizer(s);
for(int i=0;i<n;i++)
{
int x=Integer.parseInt(st.nextToken());
if(x==2)
twos++;
if(x>2)
GT2++;
}
long ans=(GT2*(GT2-1))/2+GT2*twos;
System.out.println(ans);
}
}
}

https://www.codechef.com/viewsolution/13198472

Can anyone prove me mathematically why do we need to add (number of 2’s)(number of elements greater than 2)
to (c
(c-1)/2). Hope you do prove mathematically??