about summary refs log tree commit diff
path: root/others/easy20160714/15.c
blob: fc9c8e4194c79af044a2bfe48545ca199e9497d0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>

int main()
{
	FILE *fi = fopen("INP.TXT", "r"), *fo = fopen("OUT.TXT", "w");
	int n, m, i, *a, *b, x, y;
	char signal;

	fscanf(fi, "%d %d", &n, &m);
	a = malloc(n * sizeof(int));
	b = malloc(n * sizeof(int));

	for (i = 0; i < n; i++)
		fscanf(fi, "%d %d", a + i, b + i);

	for (i = 0; i < m; i++) {
		fscanf(fi, "%hhd %d %d", &signal, &x, &y);
		x--;

		b[x] += (signal ^ 1) ? -y : y;
		if (b[x] < a[x]) {
			fprintf(fo, "BUY %d %d\n", x + 1, a[x] - b[x]);
			b[x] = a[x];
		}
	}

	fcloseall();

	return 0;
}