public int optimalPrice2(int[] price, int[] cost) {
		int maxGain = 0;
		int max_price = 0;
		int min = Integer.MAX_VALUE;
		int max = 0;
		for (int i : price) {
			min = Math.min(i, min);
			max = Math.max(i, max);
		}
		for (int profit = min; profit <= max; profit++) {
			int sumGain = 0;
			for (int j = 0; j < price.length; j++) {
				if (price[j] >= profit) {
					int gain = profit - cost[j];
					if (gain >= 0) {
						sumGain += gain;
					}
				}
			}
			if (maxGain < sumGain || maxGain == sumGain && max_price > profit) {
				maxGain = sumGain;
				max_price = profit;
			}
		}

		return max_price;
	}