ICPC Dhaka Regional 2020 Online Preliminary Contest - Hosted by CSE, DU problem E. Alice, Bob and the array Solution
Solution in C++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll tst,n,ca=1;
cin>>tst;
while(tst--)
{
cin>>n;
ll arr[n+4],cnt=0;
for(ll i=0; i<n; i++)
{
cin>>arr[i];
if(arr[i]>0) cnt+=arr[i];
}
if(cnt>=1)
{
ll sign=-1,ok=0;
for(ll i=0; i<n; i++)
{
if(arr[i]==0) continue;
else if(sign==-1 && arr[i]>0)
{
sign=1;
}
else
{
if(arr[i]>0 && sign==0)
{
ok++;
sign=1;
}
else if(arr[i]<0 && sign==1) sign=0;
}
}
printf("Case %lld: %lld %lld\n",ca++,cnt,ok);
}
else
{
sort(arr,arr+n);
printf("Case %lld: %lld 0\n",ca++,arr[n-1]);
}
}
return 0;
}
No comments