Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- int O, o, A, a, B, b, AB, ab; //upper case is positive
- final int Of, of, Af, af, Bf, bf, ABf, abf;
- int c = 0;
- o = s.nextInt();
- O = s.nextInt();
- a = s.nextInt();
- A = s.nextInt();
- b = s.nextInt();
- B = s.nextInt();
- ab = s.nextInt();
- AB = s.nextInt();
- //next line
- of = s.nextInt();
- Of = s.nextInt();
- af = s.nextInt();
- Af = s.nextInt();
- bf = s.nextInt();
- Bf = s.nextInt();
- abf = s.nextInt();
- ABf = s.nextInt();
- if(o >= of) { //o- is most restrictive
- o -= of; c += of;
- }
- else {
- c += o; o = 0;
- }
- //o+
- if(O >= Of) {
- c += Of; O -= Of;
- }
- else if((o + O) >= Of) {
- c += Of; o -= (Of - O); O = 0;
- }
- else {
- c += (o + O); o = 0; O = 0;
- }
- //a-
- if(a >= af) {
- c += af; a -= af;
- }
- else if((o + a) >= af) {
- c += af; o -= (af - a); a = 0;
- }
- else {
- c += a; a = 0;
- }
- //a+
- if(A >= Af) {
- c += Af; A -= Af;
- }
- else if((A + a) >= Af) {
- c += Af; a -= (Af - A); A = 0;
- }
- else if((A + a + O) >= Af) {
- c += Af; O -= (Af - a - A); a = 0; A = 0;
- }
- else if((A + a + O + o) >= Af) {
- c += Af; o -= (Af - a - A - O); O = 0; a = 0; A = 0;
- }
- else {
- c += (O + o + A + a); O = 0; o = 0; A = 0; a = 0;
- }
- //b-
- if(b >= bf) {
- c += bf; b -= bf;
- }
- else if((o + b) >= bf) {
- c += bf; o -= (bf - b); b = 0;
- }
- else {
- c += b; b = 0;
- }
- //a+
- if(B >= Bf) {
- c += Bf; B -= Bf;
- }
- else if((B + b) >= Bf) {
- c += Bf; b -= (Bf - B); B = 0;
- }
- else if((B + b + O) >= Bf) {
- c += Bf; O -= (Bf - b - B); b = 0; B = 0;
- }
- else if((B + b + O + o) >= Af) {
- c += Bf; o -= (Bf - b - B - O); O = 0; b = 0; B = 0;
- }
- else {
- c += (O + o + B + b); O = 0; o = 0; B = 0; b = 0;
- }
- //ab (both)
- int negative = a + b + o + ab;
- int positive = A + B + O + AB;
- if(negative >= abf) {
- c += abf; negative -= abf;
- }
- else {
- c += negative; negative = 0;
- }
- if((negative + positive) >= ABf) {
- c += ABf;
- }
- else {
- c += (negative + positive);
- }
- System.out.println(c);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement