I don't know how to deal with T (test cases)value

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;
}
Here are some examples
Input:
3
8 1 6
1 6 3
3
4 5 6
1 1 6
10
5 7 63 1 48 2 9 5 7 10
5 2 7 4 1 3 6 4 8 2
20
5 3 9 7 1 6 8 4 2 3 6 5 4 7 1 2 3 6 8 7
6 4 2 9 8 7 3 1 4 7 2 5 6 5 7 1 3 5 7 4
20
5 4 7 3 6 9 8 5 1 2 3 4 7 5 3 9 8 2 1 4
6 8 7 5 3 1 4 9 6 5 8 7 2 3 6 4 2 8 9 1
20
6 5 7 1 4 8 6 3 2 5 8 4 1 3 6 8 7 4 2 6
5 4 6 2 5 9 7 4 5 3 4 8 6 6 7 3 2 6 9 4

Output:
16
16
158
98
105
106

MyOutput according to the site even though my program shows the 106 one time and not 45 times :
16
16
158
98
105
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
106
I don't know how to stop it to print out all those test cases even though i want to stop it , since the exercise wants to have 50 of them
Last edited on
In the while condition when does T-- become true?

The problem doesn't say you can't use vectors, I would prefer those to arrays. There are around 50 test cases, but you have hard wired 50.

You need to make more use of functions.

Btw Avoid using T as an identifier for a variable, in C++ speak it is used to represent template parameters.
Yeah the problem is i don't know what kind of condition do i need to stop it.

Is there a difference if i use vectors instead of arrays? I mean if i use vectors then it probably take longer for my program to compute. Isn't it safer to use arrays?

Also what do you mean about not using T as an indetifier for a variable ?
Actually 'There are around 50 test cases.' is misleading. You can safely ignore it.

In order to detect the end of input for this special case you can do this:

Instead of this:
1
2
3
4
5
6
    int T = 50;
  while (T--)
    {
       int N;
       cin >> N;
...


Write this:
1
2
3
4
5
       int N;
       while(cin >> N)
       
    {
...


TheIdeasMan wrote:
In the while condition when does T-- become true?
Actually it is true as long as T != 0.

Oh and: You should really consider to use more descriptive variable names. This way your code is nearly unreadable.
Last edited on
Normally you should prefer vectors over arrays.
It might be that an array is a few nanoseconds faster than a vector, but you probably don't need to worry about it.
https://hackernoon.com/c-investigation-arrays-vs-vectors-e9ba864468b6
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#S-performance
I mean if i use vectors then it probably take longer for my program to compute. Isn't it safer to use arrays?


No and No. There a lots of advantages to using vectors, the first being one can add items to it without having to know the size in advance. C++ has things like move semantics which basically means there is no performance overhead despite the vector being re-sized when required. And in terms of data 50 items is a drop in the ocean, std::vector works very well for millions of items.

Also what do you mean about not using T as an indetifier for a variable ?


Don't name your variable T. Sorry I used a long sentence instead of 5 words, my bad :+)
Oh ok i get it . I didin't know that you can use cin as a condition for the loop.
Also for the last one i will keep that in mind
Thank you very much it worked . I will keep in mind everything that you told me . It helped me a lot.
Registered users can post here. Sign in or register to post.