Rezultati

Up. imeNalogaJezikRezultatČas oddaje
scnm1-2018 Arbitraža Java 100/100OK 13. okt '18 @ 14:37

Test Točke Porabljen spomin Porabljen čas Status
#1 11/11 33,738 MiB 0,000 s OK
#2 11/11 66,672 MiB 0,254 s OK
#3 11/11 49,426 MiB 0,000 s OK
#4 11/11 52,309 MiB 0,261 s OK
#5 11/11 49,121 MiB 0,087 s OK
#6 11/11 55,141 MiB 0,083 s OK
#7 11/11 52,938 MiB 0,057 s OK
#8 11/11 34,492 MiB 0,000 s OK
#9 12/12 38,016 MiB 0,000 s OK

Ocenjevani program (n1.java):
import java.util.*;
import java.io.*;

public class n1 {
	public static long f(int l1, int l2, int k, int[] q1, int[] q2) {
		long best = 0;
		for (int countl = 0; countl <= k; countl++) {
			int cl = Math.min(countl, l1);
			int countr = k - countl;
			int cr = Math.min(countr, l2);
			long sum = 0;
			for (int i = 0; i < Math.min(cl, cr); i++) {
				sum += q1[i] * q2[i];
			}
			for (int i = Math.min(cl, cr); i < cl; i++) {
				sum += q1[i];
			}
			for (int i = Math.min(cl, cr); i < cr; i++) {
				sum += q2[i];
			}
			// System.out.println(sum+" "+cl+" "+cr);
			best = Math.max(best, sum * Math.max(cl, cr));
		}
		return best;
	}

	public static void main(String[] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(in.readLine());
		int n = Integer.parseInt(st.nextToken());
		int m = Integer.parseInt(st.nextToken());
		int k = Integer.parseInt(st.nextToken());
		int num = Math.max(m, n);
		long[] q1 = new long[Math.max(k, num)];
		st = new StringTokenizer(in.readLine());
		for (int i = 0; i < n; i++) {
			q1[i] = -Integer.parseInt(st.nextToken());
		}
		long[] q2 = new long[Math.max(k, num)];
		st = new StringTokenizer(in.readLine());
		for (int i = 0; i < m; i++) {
			q2[i] = -Integer.parseInt(st.nextToken());
		}
		Arrays.sort(q1);
		Arrays.sort(q2);
		for (int i = 0; i < num; i++) {
			q1[i] = -q1[i];
			q2[i] = -q2[i];
		}
		if (k >= m + n) {
			long score = 0;
			long mult = Math.max(m, n);
			for (int i = 0; i < Math.min(m, n); i++) {
				score += q1[i] * q2[i];
			}
			for (int i = Math.min(m, n); i < Math.max(m, n); i++) {
				score += q1[i] + q2[i];
			}
			// System.out.println(score);
			System.out.println(score * mult);
		} else {
			long best = -1;
			long sum = 0;
			for (int i = 0; i < Math.min(n, k); i++) {
				sum += q1[i];
			}
			long len1 = Math.min(n, k);
			long len2 = 0;
			best = sum * len1;
			// System.out.println(sum);
			// System.out.println();
			for (int i = 0; i < k; i++) {// koliko iz 2. stolpca
				int prem1 = k - i - 1;
				int padd2 = i;
				// System.out.println(prem1 + " " + padd2);
				if (prem1 == padd2) {
					sum += q2[prem1] - q1[padd2];
					// System.out.println("swap");
				} else if (prem1 > padd2) {
					sum += q1[padd2] * (q2[padd2] - 1) - q1[prem1];
					// System.out.println("odstrani " + q1[prem1] + " in
					// dodaj " + q2[padd2] + " k elementu " + q1[padd2]);
				} else if (prem1 < padd2) {
					sum += q2[padd2] - q2[prem1] * (q1[prem1] - 1);
					// System.out.println("odstrani " + q1[prem1] + " od " +
					// q2[prem1] + " in dodaj " + q2[padd2]);
				}
				if (prem1 < n) {
					len1--;
				}
				if (padd2 < m) {
					len2++;
				}
				// System.out.println(len1 + " " + len2);
				if (sum * Math.max(len1, len2) > best) {
					best = Math.max(len1, len2) * sum;
				}
				// System.out.println(sum);
				// System.out.println();
			}
			System.out.println(best);
			//System.out.println(f(n, m, k, q1, q2));
		}
	}
}