So I was trying to solve the USACO Silver problem that I listed in the title. I got all of the test cases right except the last 2. I tried to see the values in the test cases but they were too large for me to grasp. Can you please tell me the flaw in my code?(Please don’t tell me how to solve it. I want to do that by myself). Thanks!!
#include <bits/stdc++.h>
using namespace std;
int n;
ifstream fin("div7.in");
ofstream fout("div7.out");
int main(){
fin >> n;
int id[n];//the id's
for(int i=0;i<n;i++){
fin>>id[i];
}
int prefix[n+1];//prefix array
prefix[0]=0;
for(int i=1;i<n+1;i++)prefix[i]=prefix[i-1]+id[i-1];
for(int j=n;j>=0;j--){//size of the subarray we are testing
for(int i=0;i<n+1;i++){
if(i+j>n)break;//if the index is outside of the array, skip
int temp=prefix[i+j]-prefix[i];//sum of the index's
if(temp%7==0){
fout << j <<"\n";//we have the max value, so give it
return 0;
}
}
}
fout << 0 << "\n";//default
return 0;
}