Блог пользователя ravelo1991

Автор ravelo1991, 12 лет назад, По-английски

In the problem B the solution is very short and probably every body make a n*log(n) solution by sorting the array and then pass over the array in O(n) to get the solution. There should'nt happen things like this: This is my code and it was Time Limit Exceded only because it was made in java.

int n =nextInt();
        long x = nextLong();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) 
            a[i]=nextLong();

        Arrays.sort(a);
        long resp = 0;
        for (int i = 0; i < n; i++)
        {
            resp += (x*a[i]);
            x--;
            x = Math.max(1,x);
        }
        out.println(resp);

I would like to know who is in charge of this king of issue?

Полный текст и комментарии »

  • Проголосовать: нравится
  • -5
  • Проголосовать: не нравится

Автор ravelo1991, 14 лет назад, По-английски

Please i need an advise. I am Mr.Pretest Passed Now and i am married with Ms.Wrong Anser After. She is giving me a green life and i don't deserve it.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +44
  • Проголосовать: не нравится