我在此程序中插入输入文件后出现分段错误错误我无法找到问题所在,有人可以帮我解决这个问题吗?(它是USACO培训牛奶的解决方案2问题)。
#include <algorithm>
#include <bitset>
#include <limits>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main ()
{
std::ifstream in ("milk2.in");
std::ofstream out ("milk2.out");
std::vector< pair <int,int> > v;
int n,i,maxn,maxs,t,ts;
in >> n;
for (i = 0; i < n; i++)
{
in >> v[i].first >> v[i].second;
}
for (i = 0; i < n; i++)
{
if (v[i].second<(v[i+1].first)
{
t=v[i+1].first-v[i].second;
if (t>maxn){
maxn=t;
}
}
else
{
ts=v[i+1].second-v[i].first;
if (ts>maxs)
{
maxs=ts;
}
}
}
out << maxs <<" "<< maxn;
return 0;
}