美团第一道题~求指导
美团第一道题,不知道错在哪里了,只通过67%,求指导
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int n;
while (cin >> n)
{
vector<int>a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
int k;
cin >> k;
int res = 0;
for (int i = 0; i < n; i++)
{
int j = i + 1;
int sum = a[i], cnt = 1;
while (j < n)
{
sum += a[j];
++cnt;
if (sum%k == 0)
res = max(res, cnt);
j++;
}
}
cout << res << endl;
}
return 0;
}
#美团#