Skip to content

Instantly share code, notes, and snippets.

@mhmoodlan
Created October 6, 2017 06:35
Show Gist options
  • Save mhmoodlan/b685122d697eb76a2642ba71313521c1 to your computer and use it in GitHub Desktop.
Save mhmoodlan/b685122d697eb76a2642ba71313521c1 to your computer and use it in GitHub Desktop.
#ElementaryMath #Implementation #Codeforces #Solved
//http://codeforces.com/contest/294/problem/A
#include <bits/stdc++.h>
#define ll long long
#define sz(v) ((int) ((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define lp(i, n) for(int i = 0; i < (int)(n); ++i)
#define rep(i, v) for(int i = 0; i < sz(v); ++i)
using namespace std;
const int MAX = 105;
int a[MAX];
int main() {
int n, m, x, y; cin>>n; lp(i, n) cin>>a[i]; cin>>m;
for(int i = 0; i < m; i++) {
cin>>x>>y;
if(x == 1 || x == n) {
if(x == 1) {
a[1] += (a[0] - y);
a[0] = 0;
} else {
a[n-1] = 0;
a[n-2] += y-1;
}
} else {
a[x-2] += y-1;
a[x] += a[x-1] - y;
a[x-1] = 0;
}
}
lp(i, n) cout << a[i] << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment