The old driver's strange Noip analog T3-zhugeliang

Source: Internet
Author: User

3. Zhuge Liang
(Zhugeliang.cpp/c/pas)
"Problem description"
XPP studies the philosophy of astronomy every day, and there are some thoughts that we cannot understand in life.
After a dull academic day, XPP opened the http://web.sanguosha.com, ready to use his beloved Zhuge Liang
abuse. Entered the eight-person status bureau, as a master, xpp decisively selected Zhuge Liang, with Zhuge Liang picked 7 people.
Why does xpp like Zhou Yu, the warlord? Because stargazing is a great skill.
Stargazing-At the beginning of the round, you can watch the X-cards at the top of the stack (x is the number of surviving characters and up to 5).
Place any number of cards in any order at the top of the stack, and the rest in any order at the bottom of the stack.
Visible stars this skill if used well then can know each other's cards. So xpp the 7 of people all light
The pine to kill.
Although the XPP star will always know the full-court hand, but he thought of such a problem: the normal stargazing should be
What's going on here?
Assuming that each card can bring a certain benefit to Zhuge Liang, then xpp now want to calculate, under certain circumstances, Zhuge Liang
What is the greatest benefit of stargazing?
But ZJR after a year of thinking, the problem has been made. Xpp thought the problem was too simple. He felt that he had
How could you have thought about it for so long? So xpp decided to strengthen the problem. Suppose that stargazing can view n cards, for every
All cards have a profit v[i], then he now has to find some cards so that he can get the benefits and the biggest.
But ZJR after two years of thinking, the problem has been made. Xpp thought the problem was too simple. He felt that he had
How could you have thought about it for so long? So xpp decided to strengthen the problem. The cards he asked to pick were the ones that were even
Continued.
But ZJR after three years of thinking, the problem has been made. Xpp thought the problem was too simple. He felt that he had
How could you have thought about it for so long? So xpp decided to strengthen the problem. According to his philosophical thinking, he thought that any
He decided not only to figure out the biggest gains, but also to figure out the big gains, the third big
Yi...... Until the K-large proceeds. He thought, this zjr this idiot should be able to do not come out of it.
But ZJR after four years of thinking, the problem has been made. Xpp thought the problem was too simple. He felt that he had
How could you have thought about it for so long? So xpp decided to strengthen the problem. He found this to be an original question,
So he added a condition, as the saying goes situation improves, then the return value is equal to its absolute values.
XPP IQ is too strong to think of such low-end problems, and then you will have to do this problem.
Input
The input file name is zhugeliang.in.
The first line contains an integer n,k.
Next line, including n integers, number i is v[i].
Output
The output file name is Zhugeliang.out.
Outputs a total of k rows, each containing an integer, and the number of line I represents the benefit of the large part I.
"Input and Output sample"
Zhugeliang.in
5 2
1 2-1-1 3

Zhugeliang.out
4
3
"Data Range"
For 10% of data, 1≤n≤200.
For 30% of data, 1≤n≤2000.
For 50% of data, 1≤n≤100000,1≤k≤1000.
For 100% of data, 1≤n≤100000,1≤k≤n,-1000≤v[i]≤1000.

——————————————————————————————

First you'll think of the prefix and set it to sum.

Because it is an absolute value, so sum[1]-sum[5]=sum[5]-sum[1]

So we can set up a two-tuple (a, b) for | SUM[A]-SUM[B] |

We can prefix and sort, the biggest is definitely (0,n), the second one is (1,n) or (0,n-1), but this will have duplicates

So we can fix each beginning, that is, in the sequence of prefixes and in, to any a<n insert all (a,n), and then get a (a, b) insert a (a,b-1), insert is loved heap

And then it's done.

"I think I'm getting better at the Orz."

"↑ A confession of Konjac konjac ↑"

1#include <iostream>2#include <string.h>3#include <cstdlib>4#include <cstdio>5#include <algorithm>6#include <cstring>7#include <vector>8#include <ctime>9#include <queue>Ten #defineIvorysi One #defineMo 10007 A #defineSiji (i,x,y) for (int i= (x); i<= (y); i++) - #defineGongzi (j,x,y) for (int j= (x); j>= (y); j--) - #defineXiaosiji (i,x,y) for (int i= (x);i< (y); i++) the #defineSigongzi (j,x,y) for (int j= (x);j> (y); j--) - #defineIvory (i,x) for (int i=head[x];i;i=edge[i].next) - #definePII pair<int,int> - #defineFi first + #defineSe Second - #defineINF 10000000 +typedefLong Longll; A using namespacestd; at intn,k; - intv[100005],sum[100005]; - intid[100005]; - structMtwo { -     intb; - }; inInlineBOOL operator<(Mtwo q,mtwo p) { -     returnABS (SUM[ID[Q.A]]-SUM[ID[Q.B]) < ABS (sum[id[p.a]]-SUM[ID[P.B]]); to } +InlineBOOLcmpintAintb) { -     returnSum[a]>Sum[b]; the } *Priority_queue<mtwo>que; $ intMain () {Panax Notoginseng #ifdef Ivorysi -Freopen ("zhugeliang.in","R", stdin); theFreopen ("Zhugeliang.out","W", stdout); + #else  AFreopen ("f1.in","R", stdin); the #endif +scanf"%d%d",&n,&k); -Siji (I,1, N) { $scanf"%d",&v[i]); $id[i]=i; -     } -Siji (I,1, N) { thesum[i]=sum[i-1]+V[i]; -     }WuyiSort (id,id+n+1, CMP); theXiaosiji (I,0, N) { - Que.push ((mtwo) {i,n}); Wu     } -Siji (I,1, K) { AboutMtwo tmp=que.top (); Que.pop (); $         if(tmp.b-1! = Tmp.a) Que.push ((mtwo) {tmp.a,tmp.b-1}); -printf"%d\n", ABS (sum[id[tmp.a]]-sum[id[tmp.b])); -     } -}

"The minister will always bear the livelihood of the people wish him to return to spring full garden"

"Outside the corridor like late Emperor drink the same as that year"

"To seek peace in the world Wu Weixin worship in front of the temple."

"The world belongs to a Han people to Liu Yan"

If my memory is good to write fast, I really want to test the history of the Department ... _ (: З"∠) _ Pity a look at the ancient Chinese eye Pain _ (: З"∠) _

Kingdoms Bright Black, kingdoms bright dead loyalty powder

Wait, how did I get this far?

The old driver's strange Noip analog T3-zhugeliang

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.