比赛 |
20101119 |
评测结果 |
AATTTTTTTT |
题目名称 |
求和 |
最终得分 |
20 |
用户昵称 |
lc |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-19 10:08:50 |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int maxn = 100010,INF = 100000000;
int A[maxn],S[maxn];
int N,K,P,Ans;
void prep()
{
scanf("%d%d%d",&N,&K,&P);
for (int i=1; i<=N; i++) scanf("%d",&A[i]);
for (int i=1; i<=N; i++) S[i] = (S[i-1] + A[i])%P;
}
void work()
{
int Ans = INF;
for (int i=1; i<=N; i++)
for (int j=0; j<i; j++)
{
int num = (S[i] - S[j] + P)%P;
if (num >=K && num <Ans) Ans = num;
}
printf("%d\n",Ans);
}
int main()
{
freopen("suma.in","r",stdin);
freopen("suma.out","w",stdout);
prep();
work();
return 0;
}