Write your question here.
So my program is pretty much ready but the problem is that the site of our university does not accept it because of my T(test cases ) value . For example if there are still remaining test cases in the site the input will be the same for the last remaining test cases while i just want to stop it and i don't know how.
Here is the exercise:
Setting Problems
As you see, setting problems for a programming contest is a tough job. There are so many things to do like creating problems, solutions, data files, verification of problem statements, writing alternate judge solutions etc. etc. Given the responsibility of creating the problemset for ‘If you can not crash judges by solutions, crash contestants by problems’ programming contest, Sultan & GolapiBaba have realized that to the backbone. Finally they agree that they will set N problems for the contest. For each of the problems, first Sultan will create the problem statement, solution & i/o data. After he finishes his work, GolapiBaba does the verification & alternate solution writing part for that particular problem. Each of them needs a particular amount of time to complete their tasks for a certain problem. Also, none of them works on more than one problem at a time. Note that, GolapiBaba can start working on a problem immediately after Sultan finishes that problem or he may wish to start that problem later.
You will be given the times that Sultan & GolapiBaba requires to complete their respective tasks for every single problem. Determine the minimum possible time required to complete the whole problemset.
Input
There are around 50 test cases. Each test case starts with a single integer N (1 ≤ N ≤ 20), the number of problems in the contest. The next line contains N integers Si (1 ≤ Si ≤ 100, 1 ≤ i ≤ N) where Si denotes the time required for Sultan to complete his tasks for problem i. The next line has N more integers Gi (1 ≤ Gi ≤ 100, 1 ≤ i ≤ N) where Gi denotes the time required for Golapibaba to complete his tasks on problem i.
Output
For each test case, print the minimum time required to complete the problemset.
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
|
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int T = 50;
while (T--)
{
int N;
cin >> N;
int array[20][20];
int S[20],G[20];
int count = 0;
int count1 = 0;
for ( int i = 0; i < N; i++)
{
cin >> S[i];
}
for ( int i = 0; i < N; i++)
{
cin >> G[i];
}
int k = N - 1;
int z =0;
for ( int i = 0; i < N; i++)
{
for ( int j = 0; j < N; j++)
{
for ( int x = 0; x < N; x++)
{
if ( G[j] == *min_element(G,G+N))
{
count++;
}
}
for ( int y = 0; y < N; y++)
{
if ( S[j] == *min_element(S,S+N))
{
count1++;
}
}
if ( count > 1 && G[j] == *min_element(G,G+N) && G[j] != 101 && S[j] == *min_element(S,S+N))
{
array[1][k] = G[j];
array[0][k] = S[j];
G[j] = 101;
S[j] = 101;
k--;
}
else if ( count1 > 1 && S[j] == *min_element(S,S+N) && S[j] != 101 && G[j] == *min_element(G,G+N))
{
array[0][z] = S[j];
array[1][z] = G[j];
S[j] = 101;
G[j] = 101;
z++;
}
else if ( G[j] == *min_element(G,G+N) && G[j] != 101)
{
array[1][k] = G[j];
array[0][k] = S[j];
G[j] = 101;
S[j] = 101;
k--;
}
else if ( S[j] == *min_element(S,S+N) && S[j] != 101 )
{
array[0][z] = S[j];
array[1][z] = G[j];
S[j] = 101;
G[j] = 101;
z++;
}
}
}
int b = 0;
int time = 0;
int temp = 0;
for ( int j = 0; j < N; j++)
{
b = array[0][j] - temp;
if ( b < 0)
{
temp = temp - array[0][j];
time += array[1][j];
temp += array[1][j];
}
else
{
time += array[0][j] - temp;
time += array[1][j];
temp = array[1][j];
}
}
cout << time << endl;
}
return 0;
}
|