TOPIC

TLE - What am i doing wrong?

Ted Carrasco asked 2 years ago

I understand that my code is highly optimized

#include <cstdio>
using namespace std;

int main() {
    int cases;
    scanf("%d", &cases);
    while(cases--) {
        int n, c;
        scanf("%d", &n);
        int V[231] = {0};
        bool flag = false;
        int search = 0;
        for (int i = 0; i < n; ++i){
            scanf("%d", &c);
            V[c]++;
        }
        for (int i = 230; i >= 20; i--){
            if(V[i] != 0) {
                search = i;
                break;
            }
        }
        for (int i = 20; i <= search - 1; ++i){
            for(int j = 0; j < V[i]; j++) {
                printf("%d ", i);
            }
        }
        for (int i = 0; i < V[search] - 1; ++i)
        {
            printf("%d ", search);
        }

        printf("%d\n", search);
    }

}

Remember not post solutions. Your post may be reviewed by our moderators.

  • feodorv replied 2 years ago

    I do not know what's wrong with URI but some time ago my alike solution runned for 0.592 ms. Now it runs for 0.904 ms which is very near to TLE. You can try fast I/O.

  • Reddy Tintaya replied 2 years ago

    use maps dude :v