4043. Magic Pen 6

本篇介绍了一个使用魔法笔修改学生分数列表的问题,目标是在保持分数总和不变的情况下尽可能多地删除不合格学生的分数记录。通过算法实现,寻找最优解。

In HIT, many people have a magic pen. Lilu0355 has a magic pen, darkgt has a magic pen, discover has a magic pen. Recently, Timer also got a magic pen from seniors.

At the end of this term, teacher gives Timer a job to deliver the list of N students who fail the course to dean's office. Most of these students are Timer's friends, and Timer doesn't want to see them fail the course. So, Timer decides to use his magic pen to scratch out consecutive names as much as possible. However, teacher has already calculated the sum of all students' scores module M. Then in order not to let the teacher find anything strange, Timer should keep the sum of the rest of students' scores module M the same.

Plans can never keep pace with changes, Timer is too busy to do this job. Therefore, he turns to you. He needs you to program to "save" these students as much as possible.

Input

The input contains several test cases.

The first line of each case contains two integer N and M, (0 < N ≤ 100000, 0 < M < 10000),then followed by a line consists of N integers a1,a2,...an (-100000000 ≤ a1,a2,...an ≤ 100000000) denoting the score of each student.(Strange score? Yes, in great HIT, everything is possible)

Output

For each test case, output the largest number of students you can scratch out.

Sample Input

2 3
1 6
3 3
2 3 6
2 5
1 3

Sample Output

1
2
0

#include<iostream>
#include<cstring>
using namespace std;
const int num=100010;
int dive[num],sum;
int main()
{
int n,m,ans,a;
while(cin>>n>>m)
{
sum=0;
ans=0;
memset(dive,-1,sizeof(dive));
dive[0]=0;
for(int i=1;i<=n;i++)
{
cin>>a;
sum=((sum+a)%m+m)%m;
if(dive[sum]==-1)
dive[sum]=i;
else
 ans=max(ans,i-dive[sum]);
}
cout<<ans<<endl;
}
return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值