Hdu 5265 Pog loves Szh II STL

Source: Internet
Author: User

POG loves Szh II

Time Limit:20 Sec

Memory limit:256 MB

Topic Connection

http://acm.hdu.edu.cn/showproblem.php?pid=5265

Descriptionpog in the game with Szh, first POG found a sequence containing n number, then he picked a number in the N number a,szh out of the pog of love, in the remaining number of n−1 also picked a number B, then Szh and POG of the value of the affectionate (a+b) The remainder of P-modulo, POG and szh of course want to make the value of love higher the better, and they want to know the highest love value is how much.

Input

Several sets of data (no more than 5 groups of n≥1000).
The first row of each group of data is two integers n (2≤n≤100000), P (1≤p≤231−1).
The next line is n integer ai (0≤ai≤231−1).

Output

For each query for each group, the output line represents the maximum affectionate value of POG and Szh.

Sample Input

4 4
1 2 3 0
4 4
0 0 2 2

Sample Output

3
2

HINT

Test instructions

Exercises

STL Dafa Good!

STL Saves the world!

Code:

//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineTest Freopen ("Test.txt", "R", stdin)#defineMAXN 2000001#defineMoD 10007#defineEPS 1e-9intNum;Charch[ -];Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;} InlinevoidPintx) {Num=0;if(!x) {Putchar ('0');p UTS ("");return;}  while(x>0) ch[++num]=x%Ten, x/=Ten;  while(Num) Putchar (ch[num--]+ -); Puts ("");}//**************************************************************************************ll A[maxn];multiset<ll>S;intMain () {//test;    intN;    ll P;  while(cin>>n>>p) {s.clear ();  for(intI=0; i<n;i++) {A[i]=read (); A[i]%=p;        S.insert (A[i]); } ll ans=0;  for(intI=0; i<n;i++) {s.erase (S.find (a[i)); Multiset<ll>::iterator It=s.lower_bound (P-A[i]); It--; Ans=max (ans, (a[i]+*it)%p); It=s.lower_bound (p*2-A[i]); It--; Ans=max (ans, (a[i]+*it)%p);        S.insert (A[i]); } cout<<ans<<Endl; }    }

Hdu 5265 Pog loves Szh II STL

Related Article

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.