当前位置:网站首页>Blue Bridge Cup_ Multiple problem_ stack_ Remainder
Blue Bridge Cup_ Multiple problem_ stack_ Remainder
2022-06-09 02:11:00 【This question AC sleep again】

//
#include<bits/stdc++.h>
using namespace std;
const int N=1111;
int in[N*N];
int main()
{
int n,k,i,j,ans,re,tt,t1,t2;
while( cin>>n>>k )
{
for( i=0;i<n;i++ ) cin>>in[i];
sort( in,in+n );
stack<int> sk[N];
for( i=0;i<n;i++ ) sk[ in[i]%k ].push( in[i] );
ans=0;
for( i=0;i<k;i++ )
{
if( sk[i].empty() ) continue;
for( j=i;j<k;j++ )
{
if( sk[j].empty() ) continue;
re=( k-i+k-j )%k;
if( re<j || sk[re].empty() ) continue; // Previous traversal
// tt=sk[i].top()+sk[j].top()+sk[re].top();
// i==j==re
tt=0;
if( !sk[i].empty() )
{
t1=sk[i].top(); sk[i].pop(); tt+=t1;
if( !sk[j].empty() )
{
t2=sk[j].top(); sk[j].pop(); tt+=t2;
if( !sk[re].empty() )
{
tt+=sk[re].top();
ans=max( ans,tt );
}
sk[j].push( t2 );
}
sk[i].push( t1 );
}
}
}
cout<<ans<<endl;
}
return 0;
}边栏推荐
- [FBCTF2019]RCEService
- Shell uppercase to lowercase
- How Bi makes SaaS products have a "sense of security" and "sensitivity" (Part I)
- Immediate consumption: spare no effort to crack down on credit investigation and repair, and radical cure of chaos calls for social synergy
- C language student course management system
- C language library card management system
- Shell disk space usage
- How to use superset to seamlessly connect with MRS for self-service analysis
- badlyserialize
- C language library management system
猜你喜欢

【Unity在Inspector面板修改值时销毁物体或组件】
![[high level knowledge] epoll implementation principle of user mode protocol stack](/img/bc/f1d8ab69145ff5f644529e292dc5d5.png)
[high level knowledge] epoll implementation principle of user mode protocol stack

Exploration and best practice of automatic verification of object acquisition technology

价值600的抖音云蹦迪直播间项目,靠直播打赏收益的风口项目源码

大四学长谈程序员

Shell loop for while (IV)

How can golang set its own gopath and import the definition file normally

Redis集群搭建

Indonesia widya robotics and Huawei cloud make the safety of construction sites visible

MySQL starts the binlog log to recover the erroneously deleted tables, data and MySQL database
随机推荐
[brush through sword finger] sword finger offer II 003 Number of 1 in the first n digit binary
MySQL starts the binlog log to recover the erroneously deleted tables, data and MySQL database
27 | 关于高水位和Leader Epoch的讨论
Codeforces Round #797 (Div. 3)A~E
Shell get IP location
Swift GCD DispatchGroup Notify wait DispatchSourceTimer Monitor system file Two apps communicate
Shell disk space usage
Live short video app development
21、ADS使用记录之E类功放设计(中)
Cve - 2022 - 30525 Replay of vulnerability
Laravel implements nearby people, shops and houses based on mongodb (LBS)
Number theory -- simple sieve method, Ehrlich sieve method and linear sieve method
C语言成绩记录簿
Shell trimloader
Young people's "new favorite" cold tea: can we start the next "Lipton era"?
Detailed explanation of floating point numbers (a thorough study of floating point numbers)
年轻人“新宠”冷泡茶:能否开启下一个“立顿时代”?
PHP replicated vulnerability
Swift GCD DispatchGroup Notify wait DispatchSourceTimer Monitor system file Two apps communicate
Servlet