-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWayO.java
More file actions
71 lines (68 loc) · 1.53 KB
/
WayO.java
File metadata and controls
71 lines (68 loc) · 1.53 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
import java.util.*;
class WayO
{
//adding comments
int outp[];
int blk[][];
int tra,bl;
int low,m;
void input()
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
outp=new int[t];
for(int l=0;l<t;l++)
{
bl=sc.nextInt();
blk=new int[bl][bl];
tra=sc.nextInt();
take();
test();
outp[l]=low;
}
for(int l=0;l<t;l++)
{
System.out.println(outp[l]);
}
}
void take()
{
for(int i=0;i<bl;i++)
{
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
for(int j=0;j<bl;j++)
{
if(j>=a && j<=b )
blk[j][i]=0;
else
blk[j][i]=1;
}
}
}
void test()
{
for(int i=0;i<bl-tra+1;i++)
{
m=0;
for(int j=0;j<bl;j++)
{
for(int k=i;k<i+tra;k++)
{
if(blk[k][j]==1)
m++;
}
}
if(i==0)
low=m;
else if(low>=m)
low=m;
}
}
public static void main(String args[])
{
WayO ob= new WayO();
ob.input();
}
}