#include <bits/stdc++.h>
using namespace std;
struct Cow
{
int p, s, t;
};
int main()
{
int n, b;
cin >> n >> b;
Cow cows[n];
for (int i = 0; i < n; i++)
{
cin >> cows[i].p >> cows[i].s;
cows[i].t = cows[i].p + cows[i].s;
}
int temp = b;
int best = 0;
for (int i = 0; i < n; i++)
{
temp = b;
int counter = 0;
for (int j = 0; j < n; j++)
{
if (j == i)
{
temp = temp - (cows[j].p / 2 + cows[j].s);
}
else
{
temp = temp - cows[j].t;
}
if (temp < 0)
{
break;
}
else
{
counter++;
}
if (counter > best)
{
best = counter;
}
}
cout << best;
return 0;
}
In the above code, when I run it, it opens up a window as usual, and let's me enter the input (shown below) fine as well.
5 24
4 2
2 0
8 1
6 3
12 5
But when I press enter, it just loads for a couple of seconds, then closes the C++ window. Any help?
Thanks in advance!