-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ4.c
More file actions
99 lines (85 loc) · 1.78 KB
/
Q4.c
File metadata and controls
99 lines (85 loc) · 1.78 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
#include<stdio.h>
int partition(int *list, int lower, int upper)
{
int pivotValue = list[lower];
int temp=0, i,j;
for(i=lower+1, j= lower+1;(i<=upper && j<=upper) ;)
{
while(list[i]<=pivotValue && i<=upper)
{
//find next value which is greater than pivotValue
++i;
}
j=i;
while(list[j]>=pivotValue && j<= upper)
{
++j;
}
if(i>upper || j>upper) {break;}
temp = list[i];
list[i]=list[j];
list[j]=temp;
++i;
++j;
}
i--;
temp= list[i];
list[i]=pivotValue;
list[lower]= temp;
return i;
}
void QuickSort(int * list, int lower, int upper)
{
if(lower >= upper)
return;
int pivot=partition(list, lower, upper);
if(upper!= lower+1)
{
QuickSort(list, lower, pivot-1);
QuickSort(list, pivot+1, upper);
}
}
int solveCase()
{
int size, numOfCurses, min_tolerance;
scanf("%d%d",&size, &numOfCurses);
int field[size][size];
int rowAr[size][2];
int colAr[size][2];
for(int i=0;i<size;i++)
{
for(int j=0;j<size;j++)
{
scanf("%d",(*(field+i)+j));
}
}
for(int i=0;i<size;i++)
{
rowAr[i][0]=0;
rowAr[i][1]=i;
for(int j=0;j<size;j++)
{
rowAr[i][0]+=field[i][j];
}
}
for(int i=0;i<size;i++)
{
colAr[i][0]=0;
colAr[i][1]=i;
for(int j=0;j<size;j++)
{
colAr[i][0]+=field[j][i];
}
}
QuickSort(rowAr,0,size);
QuickSort(colAr,0,size);
return min_tolerance;
}
int main()
{
int testCases;
scanf("%d",&testCases);
for(int i=1;i<=testCases;i++)
printf("%d\n",solveCase());
return 0;
}