Accepted solution

294A - Shaass and Oskols.

Open original problem
Source code

#include<bits/stdc++.h>

using namespace std;

int main()

{

    int n,m;

    vector<int> arr;

    cin>>n;

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

    {

        int t;

        cin>>t;

        arr.push_back(t);

    }

    cin>>m;

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

    {

        int x,y;

        cin>>x>>y;

        x--;

       if(x==0)

       {

           int t =arr[x];

           arr[x+1] +=(t-(y));

       }

        else if((x>1 || x<n-1 ))

        {

            int t =arr[x];

            arr[x-1] += (y-1) ;

            arr[x+1] +=(t-(y));

        }

        else if(x==1)

        {

            int t =arr[x];

            arr[x+1] +=(t-(y));

        }

        else if(x==n-1)

        {

            arr[x-1] += (y-1);

        }

        arr[x]=0;

    }

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

    {

        cout<<arr[i]<<endl;

    }

}
Join the discussion

Add your comment