-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCISTFILL.cs
84 lines (80 loc) · 2.66 KB
/
CISTFILL.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CodeChefHacks
{
struct CISTERN
{
public int W;
public int D;
public int H;
public int BASE;
}
class CISTFILL
{
public static void Main()
{
Run();
}
static void Run()
{
int t = int.Parse(Console.ReadLine());
while (t > 0)
{
int totalContainers = int.Parse(Console.ReadLine());
CISTERN[] c = new CISTERN[totalContainers];
int totalV = 0;
double maxK = int.MinValue;
for (int i = 0; i < totalContainers; i++)
{
string[] s = Console.ReadLine().Split();
c[i].BASE = int.Parse(s[0]);
c[i].H = int.Parse(s[1]);
c[i].W = int.Parse(s[2]);
c[i].D = int.Parse(s[3]);
totalV += c[i].D * c[i].H * c[i].W;
if (c[i].BASE + c[i].H > maxK)
maxK = c[i].BASE + c[i].H;
}
int V = int.Parse(Console.ReadLine());
if (totalV < V)
Console.WriteLine("OVERFLOW");
else
{
double minK = 0;
while (Math.Round(minK, 4) < Math.Round(maxK, 4))
{
double midPoint = minK + (maxK - minK) / 2.0;
double possibleVolume = 0.0;
for (int i = 0; i < totalContainers; i++)
{
if (c[i].BASE < midPoint)
{
if (c[i].H + c[i].BASE > midPoint)
{
possibleVolume += c[i].D * c[i].W * (midPoint - c[i].BASE);
}
else
{
possibleVolume += c[i].H * c[i].W * c[i].D;
}
}
}
if (possibleVolume < V)
{
minK = midPoint;
}
else
{
maxK = midPoint;
}
}
Console.WriteLine(String.Format("{0:0.00}", minK));
}
t--;
}
Console.ReadLine();
}
}
}