I wrote a solution to the problem, sample data worked but there was a runtime problem. I was sure its because of the data constraints. So, I read the editorial after which I felt my programming proficiency is lacking, I have completed a course on Data Structures at my college, have not done anything on Algorithms yet.

The code I wrote

```
#include <iostream>
using namespace std;
struct timeinterval {
int x,y;
int flag;
};
int main (void) {
int n, groups, aliens[100][100], i, j, k, ans = 0;
timeinterval t[100];
cin >> n;
for (i = 0; i < n; i++) {
cin >> t[i].x >> t[i].y;
t[i].flag = 0;
}
//cout << "Groups" <<endl;
cin >> groups;
for (i = 0; i<groups; i++) {
//cout << "Group" << i+1 <<endl;
cin >> aliens [i][0];
for (j = 1; j<=aliens[i][0]; j++) {
cin >> aliens[i][j];
}
}
for (i = 0; i < groups; i++) {
for ( j = 1; j <= aliens[i][0]; j++) {
for (k = 0; k < n; k++) {
if (aliens[i][j] >= t[k].x && aliens [i][j] <= t[k].y && t[k].flag == 0) {
t[k].flag = 1;
ans++;
}
}
}
cout << ans << endl;
ans = 0;
for (k = 0; k < n; k++)
t[k].flag = 0;
}
return 0;
}
```

My question is,

1> Is it possible to solve this question like this?

2> Could you point me in the direction of something which I could read and practice for better coding.