1073D. Berland Fair - Codeforces Solution C++

  Problem Link : 1073D. Berland Fair 


✅ C++ Solution :

 
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
 
int main()
{
 
  ll n,t;
  cin>>n>>t;
  ll arr[n+1];
  for(ll i=1;i<=n;i++)
    cin>>arr[i];
 
  ll cnt=0;
  ll ans=0;
  ll sum=0;
  ll turns;
  do
  {
    sum=0;
    cnt=0;
    for(ll i=1;i<=n;i++)
    {
      if(sum+arr[i]<=t)
      {
        cnt++;
        sum+=arr[i];
      }
    }
    if(sum==0)
        break;
    turns = t / sum;
    ans+=cnt*turns;
    t-=(turns * sum);
 
  }while(cnt!=0);
 
  cout<<ans;
 
 
 
}

 

Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook. 

😇Happy Learning!!