Devious Minister

All submissions for this problem are available.
The government of Siruseri has just commissioned one of the longest and most modern railway routes in the world. This route runs the entire length of Siruseri and passes through many of the big cities and a large number of small towns and villages in Siruseri. The railway stations along this route have all been constructed keeping in mind the comfort of the travellers. Every station has big parking lots, comfortable waiting rooms and plenty of space for eateries. The railway authorities would like to contract out the catering services of these eateries. The Siruseri Economic Survey has done a through feasibility study of the different stations and documented the expected profits (or losses) for the eateries in all the railway stations on this route. The authorities would like to ensure that every station is catered to. To prevent caterers from bidding only for profitable stations, the authorities have decided to give out catering contracts for contiguous segments of stations. The minister in charge realises that one of the bidders is his bitter adversary and he has decided to hand out as useless a segment as possible to him. On the other hand, he does not want to be seen to be blatantly unfair by handing out a large lossmaking section to the adversary. Instead he wants to find the largest segment whose sum is closest to $0$, so that his adversary spends all his time running a large number of canteens and makes either a small loss or a small profit or, even better, nothing at all! In other words, if the profits/losses at the stations are $p_1, p_2, ..., p_N$ the minister would like to handover a sequence $i, i+1, ..., j$ such that the absolute value of $p_i + p_{i+1} + ... + p_j$ is minimized. If there is more than one sequence with this minimum absolute value then he would like to hand over the longest one. For example, suppose there are $8$ stations along the line and their profitability is as follows: $ $ Station 1 2 3 4 5 6 7 8 Expected Profits 20 90 30 20 80 70 60 125 $ $ If the adversary is awarded the section $1$ through $4$, he will make a net profit of $20$. On the other hand if he is given stations $6, 7$ and $8$, he will make loss of $5$ rupees. This is the best possible value. ###Input: The first line of the input contains a single integer $N$ indicating the number of stations. The next $N$ lines (lines $2, 3, ..., N+1$) describe the profitability of the $N$ stations. Line $i+1$ contains a single integer denoting the expected profit at station $i$. ###Output: The first line contains a single integer indicating the minimum possible profit/loss among all segments. The second line contains two integers indicating the starting and ending point of the longest sequence with this minimum profit/loss. If there is more than one answer, it suffices to print one. ###Constraints:  $1 \leq N \leq 100000$.  $10^9 \leq p_i \leq 10^9$ ###Subtasks  **Subtask 1**  40%  $1 \leq N \leq 4000$  **Subtask 2**  60%  Original constraints ###Sample Input 8 20 90 30 20 80 70 60 125 ###Sample Output 5 6 8Author:  admin2 
Date Added:  17092018 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions