-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy path1426E.java
149 lines (134 loc) · 4.2 KB
/
1426E.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//https://codeforces.com/contest/1426/problem/E
/*
* (c) Saurav Prateek
*/
import java.util.*;
import java.io.*;
public class RockPaperScissors {
public static int max1 = 0;
public static void compute(int[] al, int[] be, int[] vis, int cval){
int allv = 1;
for(int i=1; i<=6; i++){
if(vis[i] == 0){
vis[i] = 1;
if(i==1){
int addv = Math.min(al[0], be[0]);
int nval = cval + addv;
al[0] -= addv;
be[0] -= addv;
compute(al,be,vis,nval);
al[0] += addv;
be[0] += addv;
}
else if(i==2){
int addv = Math.min(al[0], be[2]);
int nval = cval + addv;
al[0] -= addv;
be[2] -= addv;
compute(al,be,vis,nval);
al[0] += addv;
be[2] += addv;
}
else if(i==3){
int addv = Math.min(al[1], be[0]);
int nval = cval + addv;
al[1] -= addv;
be[0] -= addv;
compute(al,be,vis,nval);
al[1] += addv;
be[0] += addv;
}
else if(i==4){
int addv = Math.min(al[1], be[1]);
int nval = cval + addv;
al[1] -= addv;
be[1] -= addv;
compute(al,be,vis,nval);
al[1] += addv;
be[1] += addv;
}
else if(i==5){
int addv = Math.min(al[2], be[1]);
int nval = cval + addv;
al[2] -= addv;
be[1] -= addv;
compute(al,be,vis,nval);
al[2] += addv;
be[1] += addv;
}
else if(i==6){
int addv = Math.min(al[2], be[2]);
int nval = cval + addv;
al[2] -= addv;
be[2] -= addv;
compute(al,be,vis,nval);
al[2] += addv;
be[2] += addv;
}
allv = 0;
vis[i] = 0;
}
}
if(allv == 1){
max1 = Math.max(max1, cval);
}
}
public static void main(String[] args) {
FastReader sc1 = new FastReader();
int n = sc1.nextInt();
int[] al = new int[3];
int[] be = new int[3];
al[0] = sc1.nextInt();
al[1] = sc1.nextInt();
al[2] = sc1.nextInt();
be[0] = sc1.nextInt();
be[1] = sc1.nextInt();
be[2] = sc1.nextInt();
int[] vis = new int[7];
int[] oal = new int[3];
int[] obe = new int[3];
for(int i=0; i<3; i++){
oal[i] = al[i];
obe[i] = be[i];
}
compute(al,be,vis,0);
max1 = n - max1;
int max2 = Math.min(oal[0], obe[1]) + Math.min(oal[1], obe[2]) + Math.min(oal[2], obe[0]);
System.out.print(max1+" "+max2);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}