public static void main(String[] args) {
		Random gen = new Random();

		int n = 40, k = 4;
		// random tests for n = 40, k = 4 for 100 times/
		for (int times = 0; times < 100; ++times) {
			List<Integer> A = new ArrayList<Integer>();
			for (int i = 0; i < n; ++i) {
				A.add(gen.nextInt(100));
			}

			System.out.println("n = " + n + ", k = " + k);
			System.out.println(max_k_pairs_profits(A, k));
			assert (check_ans(A, k) == max_k_pairs_profits(A, k));
		}

		if (args.length == 1) {
			n = Integer.valueOf(args[0]);
			k = gen.nextInt(n >> 1) + 1;
		} else if (args.length == 2) {
			n = Integer.valueOf(args[0]);
			n = Integer.valueOf(args[1]);
		} else {
			n = gen.nextInt(10000) + 1;
			k = gen.nextInt(n >> 1) + 1;
		}

		List<Integer> A = new ArrayList<Integer>();

		for (int i = 0; i < n; ++i) {
			A.add(gen.nextInt(100));
		}

		System.out.println("n = " + n + ", k = " + k);
		System.out.println(max_k_pairs_profits(A, k));
	}