### Re: 10131 - Is Bigger Smarter?

Posted:

**Fri Jan 16, 2015 12:14 am**You are right, your code is correct on the sample input.

Sort by increasing weight.

A O(n * n) LDS by IQ is fast enough for this problem.

Initialize each element of count to 1, and each element of previous to -1.Then print mx. Then print the path in reverse using the previous array starting at best_index, using the original id's that you kept track of during the sort.

Sort by increasing weight.

A O(n * n) LDS by IQ is fast enough for this problem.

Initialize each element of count to 1, and each element of previous to -1.

Code: Select all

```
int mx = 1, best_index;
for(int j = 1; j < n; j++)
for(int i = 0; i < j; i++)
if(e[i].weight < e[j].weight && e[i].iq > e[j].iq)
if(1 + count[i] > count[j]) {
count[j] = 1 + count[i];
previous[j] = i;
if ( count[j] > mx ) {
mx = count[j];
best_index = j;
}
}
```