about summary refs log tree commit diff
path: root/others/easy20160714/03.c
blob: bec1804e77c000ffca6c6c743af4e5b93d456f9c (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
#include <stdio.h>
#include <stdlib.h>

int main()
{
	FILE *f = fopen("INP.TXT", "r");
	char n, i;
	short *a, b;
	long k;

	fscanf(f, "%hhd %ld", &n, &k);
	a = malloc(n * sizeof(short));

	for (i = 0; i < n; i++)
		fscanf(f, "%hd", a + i);

	for (i = 0; i < n && k > 0; i++) {
		fscanf(f, "%hd", &b);
		k -= b - a[i];
	}
	
	fclose(f);

	f = fopen("OUT.TXT", "w");

	fprintf(f, "%hhd\n", (n - i) ? i : -1);

	fclose(f);

	return 0;
}