Accepted solution

686A - Free Ice Cream

Open original problem
Source code

#include <iostream>

#include<vector>

#include<string>

#include<math.h>

/***** S. M. Sabiul Hajjaj Sabit *****/

using namespace std;

template <typename T>long long int power(T a, T b)

{

    long long int pow=1;

    for(int i=0; i<b; i++)

    {

        pow *= a;

    }

    return pow;

}

///*********Write Code From Here*********///

int main()

{

    long long int n,x;

    cin>>n>>x;

    int dis=0;

    for(int i=0; i<n; i++)

    {

        char c;

        int t;

        cin>>c>>t;

        if(c=='+')

        {

            x+=t;

        }

        else

        {

            if(x>=t)

            {

                x-=t;

            }

            else

            {

                dis++;

            }

        }

    }

    cout<<x<<" "<<dis<<endl;

}
Join the discussion

Add your comment