Advertisement
Stuffbyliang

Untitled

Feb 11th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.90 KB | None | 0 0
  1. import java.util.*;
  2. public class Main {
  3.     public static void main(String[] args) {
  4.         Scanner s = new Scanner(System.in);
  5.         int O, o, A, a, B, b, AB, ab; //upper case is positive
  6.         final int Of, of, Af, af, Bf, bf, ABf, abf;
  7.         int c = 0;
  8.  
  9.         o = s.nextInt();
  10.         O = s.nextInt();
  11.         a = s.nextInt();
  12.         A = s.nextInt();
  13.         b = s.nextInt();
  14.         B = s.nextInt();
  15.         ab = s.nextInt();
  16.         AB = s.nextInt();
  17.         //next line
  18.         of = s.nextInt();
  19.         Of = s.nextInt();
  20.         af = s.nextInt();
  21.         Af = s.nextInt();
  22.         bf = s.nextInt();
  23.         Bf = s.nextInt();
  24.         abf = s.nextInt();
  25.         ABf = s.nextInt();
  26.  
  27.         if(o >= of) { //o- is most restrictive
  28.             o -= of; c += of;
  29.         }
  30.         else {
  31.             c += o; o = 0;
  32.         }
  33.  
  34.         //o+
  35.         if(O >= Of) {
  36.             c += Of; O -= Of;
  37.         }
  38.         else if((o + O) >= Of) {
  39.             c += Of; o -= (Of - O); O = 0;
  40.         }
  41.         else {
  42.             c += (o + O); o = 0; O = 0;
  43.         }
  44.  
  45.         //a-
  46.         if(a >= af) {
  47.             c += af; a -= af;
  48.         }
  49.         else if((o + a) >= af) {
  50.             c += af; o -= (af - a); a = 0;
  51.         }
  52.         else {
  53.             c += a; a = 0;
  54.         }
  55.  
  56.         //a+
  57.         if(A >= Af) {
  58.             c += Af; A -= Af;
  59.         }
  60.         else if((A + a) >= Af) {
  61.             c += Af; a -= (Af - A); A = 0;
  62.         }
  63.         else if((A + a + O) >= Af) {
  64.             c += Af; O -= (Af - a - A); a = 0; A = 0;
  65.         }
  66.         else if((A + a + O + o) >= Af) {
  67.             c += Af; o -= (Af - a - A - O); O = 0; a = 0; A = 0;
  68.         }
  69.         else {
  70.             c += (O + o + A + a); O = 0; o = 0; A = 0; a = 0;
  71.         }
  72.  
  73.         //b-
  74.         if(b >= bf) {
  75.             c += bf; b -= bf;
  76.         }
  77.         else if((o + b) >= bf) {
  78.             c += bf; o -= (bf - b); b = 0;
  79.         }
  80.         else {
  81.             c += b; b = 0;
  82.         }
  83.  
  84.         //a+
  85.         if(B >= Bf) {
  86.             c += Bf; B -= Bf;
  87.         }
  88.         else if((B + b) >= Bf) {
  89.             c += Bf; b -= (Bf - B); B = 0;
  90.         }
  91.         else if((B + b + O) >= Bf) {
  92.             c += Bf; O -= (Bf - b - B); b = 0; B = 0;
  93.         }
  94.         else if((B + b + O + o) >= Af) {
  95.             c += Bf; o -= (Bf - b - B - O); O = 0; b = 0; B = 0;
  96.         }
  97.         else {
  98.             c += (O + o + B + b); O = 0; o = 0; B = 0; b = 0;
  99.         }
  100.  
  101.         //ab (both)
  102.         int negative = a + b + o + ab;
  103.         int positive = A + B + O + AB;
  104.         if(negative >= abf) {
  105.             c += abf; negative -= abf;
  106.         }
  107.         else {
  108.             c += negative; negative = 0;
  109.         }
  110.  
  111.         if((negative + positive) >= ABf) {
  112.             c += ABf;
  113.         }
  114.         else {
  115.             c += (negative + positive);
  116.         }
  117.  
  118.         System.out.println(c);
  119.  
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement