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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <queue>

#define MIN(a,b) ((a) < (b)) ? (a) : (b)
#define MAX(a,b) ((a) > (b)) ? (a) : (b)

using namespace std;

int main(void) {
	srand (time(NULL));
        uint16_t n, m, o = 0;
        scanf("%" SCNu16 " %" SCNu16, &n, &m);
	priority_queue< uint32_t > c;
	uint32_t x;
	uint64_t sa = 0, sc = 0;

        for (int i = 0; i < n; i++)
	{
		scanf("%" SCNu32, &x);
		sa += x;
	}
	for (int j = 0; j < m; j++)
        {
                scanf("%" SCNu32, &x);
		c.push(x);
	}
	while(!c.empty())
	{
		o++;
		x = c.top();
		c.pop();
		sc += x;
		float y = 1.06 + 0.00001 * (rand() % 3000);
		if (sc >= sa * y)
		{
			printf("%" PRIu16 "\n", o);
			return 0;
		}
	}
	printf("NIE\n");
        return 0;
}