CODING FOR FUN -EDITORIAL

Problem link:https://www.codechef.com/CFUN2020/problems/CODSTAN2
Setter:Ankur Pandey
Tester:Ankur Pandey

Difficulty:
Simple
Time Complexity:O(n)
Problem:…
Explanation: In this problem you just have to know how many Parrots are there on each branch after each shot. A good trick for the first and the last branch would be to define branch 0 and n + 1. In this way the parrots that fly away sit on these branch and you don’t need to worry about accessing some element outside the range of your array.
#include

#include

using namespace std;

int main(){

int n,m,a[101]={0};

int x,y,i;

cin>>n;

for(i=1;i<=n;i++)

    cin>>a[i];

cin>>m;

for(i=1;i<=m;i++){

    cin>>x>>y;

    a[x-1]+=y-1;

    a[x+1]+=a[x]-y;

    a[x]=0;

}

for(i=1;i<=n;i++)

    cout<<a[i]<<endl;

return 0;

}