My issue
I just tried iterating over fallen wickets and tried to put those batsman in positions which will benefit the most for total score.
My code
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int w[n];
vector<int> f(n+1,0);
for(int i=1;i<n;i++)
{
cin>>w[i];
f[w[i]]=1;
}
vector<int> b(n+1,0);
int s = 1;
for(int i=1;i<=n-1;i++)
{
if(w[i]>=i+1)
{
b[s]=w[i];
s=i+1;
}
else
{
b[i+1]=w[i];
}
}
for(int i=1;i<=n;i++)
{
if(f[i]==0) b[s]=i;
}
int ans = 0;
for(int i=1;i<=n;i++)
{
ans += max(i,b[i]);
}
cout<<ans<<endl;
}
return 0;
}
Problem Link: ODI Cricket Practice Coding Problem - CodeChef