INSULENG - Insulation
Give N bricks and a sequence a1...an as the insulation of them. If we arrange the bricks in that order into a wall then the insulation of the wall is a1 + a2 + ... + aN + max(0, a2 - a1) + max(0, a3 - a2) + ... + max(0, aN - aN - 1). Your task is to arrange the bricks so that the insulation of the wall is maximum.
- The first line is N (1 <= N <= 105).
- In each of the next N lines, the ith line is ai-1
- The maximum insulation of the wall.
Input is poorly formatted.
I think this problems is set as a challenge (my score for challenges isn't adding up). Please correct that.
The example is 24 if we arrange the bricks like this: 1 5 4 7 ;)
the example is 23 for me...
i think such test cases went for me to TLE
How did you checked all permutations for N=10^5 :O
I dont understand scoring..
@cegprakash: you need not check for all permutations! :P
|Cluster:||Cube (Intel G860)|
|Languages:||All except: ASM32-GCC ASM64 GAWK MAWK BC C-CLANG CPP14 CPP14-CLANG COBOL COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH GOSU GRV JS-MONKEY KTLN NIM NODEJS OBJC OBJC-CLANG OCT PICO PROLOG PYPY PY_NBC R RACKET RUST CHICKEN SED SQLITE SWIFT UNLAMBDA VB.NET|