-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem270C.java
More file actions
180 lines (169 loc) · 3.43 KB
/
Copy pathProblem270C.java
File metadata and controls
180 lines (169 loc) · 3.43 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package CodeForces;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Problem270C
{
public static void main(String[] args) throws IOException
{
fastinput.init(System.in);
int n = fastinput.nextInt();
String[] sizes = new String[n];
for (int i = 0; i < n; i++)
{
sizes[i] = fastinput.nextline();
}
if (n == 1)
{
String[] pairs = sizes[0].split(" ");
int k = Integer.valueOf(pairs[0]);
int a = Integer.valueOf(pairs[1]);
if (a <= 4)
System.out.println(k+1);
else
{
int nk = k+2;
BigInteger base = new BigInteger("2");
System.out.println("Past base initialization.");
base = base.pow(k);
System.out.println("Past initial power set.");
base = base.multiply(base);
System.out.println("Past base*base.");
BigInteger nsq = new BigInteger(Integer.toString(a));
BigInteger oldsize = base.multiply(nsq);
System.out.println(oldsize);
while (true)
{
BigInteger upperbase = new BigInteger("2");
upperbase = upperbase.pow(nk);
upperbase = upperbase.multiply(upperbase);
if (upperbase.compareTo(oldsize) >= 0)
{
break;
}
else
{
nk++;
}
}
System.out.println(nk);
}
}
else
{
Arrays.sort(sizes);
int[] ks = new int[n];
int[] as = new int[n];
for (int q = 0; q < sizes.length; q++)
{
String[] splitter = sizes[q].split(" ");
ks[q] = Integer.valueOf(splitter[0]);
as[q] = Integer.valueOf(splitter[1]);
}
for (int j = 0; j+1 < sizes.length; j++)
{
int firstk = ks[j];
int firsta = as[j];
int secondk = ks[j+1];
int seconda = as[j+1];
int boxes;
if (secondk == firstk + 1)
{
if (firsta % 4 == 0)
boxes = firsta >> 2;
else
boxes = (firsta >> 2) + 1;
if (boxes > seconda)
{
as[j+1] = boxes;
}
}
else
{
while(true)
{
if (firsta % 4 == 0)
{
boxes = firsta >> 2;
}
else
{
boxes = (firsta >> 2)+1;
}
if (secondk == firstk + 1)
{
if (boxes > seconda)
{
as[j+1] = boxes;
}
break;
}
else
{
firstk++;
firsta = boxes;
}
}
}
}
int lastk = ks[n-1];
int lasta = as[n-1];
if (lasta <= 4)
System.out.println(lastk+1);
else
{
long nk = lastk+2;
long oldsize = lastk*lasta;
long higherbox = 0;
while (true)
{
higherbox = (nk)*(nk);
if (higherbox >= oldsize)
{
break;
}
else
{
nk++;
}
}
long result = (long)Math.sqrt(higherbox);
System.out.println(result);
}
}
}
public static class fastinput
{
static BufferedReader bf;
static StringTokenizer st;
static void init(InputStream input)
{
bf = new BufferedReader(new InputStreamReader(input));
st = new StringTokenizer("");
}
static String nextline() throws IOException
{
return bf.readLine();
}
static String next() throws IOException
{
while (!st.hasMoreTokens())
{
st = new StringTokenizer(bf.readLine());
}
return st.nextToken();
}
static int nextInt() throws IOException
{
return Integer.parseInt(next());
}
static long nextLong() throws IOException
{
return Long.parseLong(next());
}
}
}