ok

this is my whole code

This is a relatively famous problem: Barn repair

It was a dark and stormy night that ripped the roof and gates off the stalls that hold Farmer John's cows. Happily, many of the cows were on vacation, so the barn was not completely full.

The cows spend the night in stalls that are arranged adjacent to each other in a long line. Some stalls have cows in them; some do not. All stalls are the same width.

Farmer John must quickly erect new boards in front of the stalls, since the doors were lost. His new lumber supplier will supply him boards of any length he wishes, but the supplier can only deliver a small number of total boards. Farmer John wishes to minimize the total length of the boards he must purchase.

Given M (1 <= M <= 50), the maximum number of boards that can be purchased; S (1 <= S <= 200), the total number of stalls; C (1 <= C <= S) the number of cows in the stalls, and the C occupied stall numbers (1 <= stall_number <= S), calculate the minimum number of stalls that must be blocked in order to block all the stalls that have cows in them.

Print your answer as the total number of stalls blocked.

Code:

/*
ID: mhayter1
PROG: barn1
LANG: C++
*/
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
int main()
{
int m=0,s=0,c=0, temp=0, gap=0, min=0, max=0,high=0, sum=0,l=0;
/*
ifstream fin("barn1.in", ios::in);
ofstream fout("barn1.out", ios::out);
if(!fin)
{
cerr << "File could not be opened\n";
exit(1);
}
if(!fout)
{
cerr << "File could not be opened\n";
exit(1);
}
*/
cin >> m >> s >> c;
if(m>=c)
{
cout << c << "\n";
return 0;
}
vector<int> tempArray(s);
vector<int> cowloc(c);
vector<int> gaps(m-1);
for(int i=0; i<s; i++)
tempArray[i]=0;
for(int i=0; i<c; i++)
{
cin >> temp;
tempArray[temp-1]=1;
}
high=0;
for(int i=0; i<s; i++)
{
if(tempArray[i]==1)
{
cowloc[high]=i+1;
high++;
}
}
min=cowloc[0];
max=cowloc[high-1];
//Error in this block of code
for(int i=min; i<max-1; i++)
{
gap=0;
for(int k=cowloc[i]; tempArray[k+1]==0; k++)
{
gap++;
l=k;
}
for(int j=m-2; j>-1; j--)
{
if(gap>gaps[j])
{
gaps[j]=gap;
break;
}
}
}
for(int j=m-2; j>-1; j--)
{
cout << "G= " << gaps[j] << "\n";
sum+=gaps[j];
}
cout << "max= " << max << "\n";
cout << "min= " << min << "\n";
cout <<"sum= " << sum << "\n";
cout << max-min+1-sum << "\n";
int y;
cin >>y;
return 0;
}

does that help at all?