Problem p03000 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define _GLIBCXX_DEBUG
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<long long, long long>
#define ppii pair<long long, pair<long long, long long>>
#define all(x) (x).begin(), (x).end()
#define rep(x) for (int i = 0; i < (x); i++)
#define repj(x) for (int j = 0; j < (x); j++)
#define REP(i, x) for (int(i) = 0; (i) < (x); (i)++)
#define rrep(x) for (int i = (x); i >= 0; i--)
#define mod 1000000007
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;
typedef vector<vector<long long>> vii;
typedef long long lint;
typedef long long ll;
lint qp(int a, ll b) {
  int ans = 1;
  do {
    if (b & 1)
      ans = 1ll * ans * a;
    a = 1ll * a * a;
  } while (b >>= 1);
  return ans;
}
lint qp(int a, ll b, int mo) {
  int ans = 1;
  do {
    if (b & 1)
      ans = 1ll * ans * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return ans;
}
lint gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
long long INF = 1e14;
const int MAX_N = 1 << 17;
const int cf = 100010;
///////////////////////////////////////////////////////////////////////////////
int L[100000];
int main(void) {
  int n, x;
  cin >> n >> x;
  rep(n) cin >> L[i];
  int c = 0;
  int lyn = 0;
  while (lyn <= x) {
    lyn += L[c];
    c++;
  }
  cout << c << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define _GLIBCXX_DEBUG
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<long long, long long>
#define ppii pair<long long, pair<long long, long long>>
#define all(x) (x).begin(), (x).end()
#define rep(x) for (int i = 0; i < (x); i++)
#define repj(x) for (int j = 0; j < (x); j++)
#define REP(i, x) for (int(i) = 0; (i) < (x); (i)++)
#define rrep(x) for (int i = (x); i >= 0; i--)
#define mod 1000000007
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;
typedef vector<vector<long long>> vii;
typedef long long lint;
typedef long long ll;
lint qp(int a, ll b) {
  int ans = 1;
  do {
    if (b & 1)
      ans = 1ll * ans * a;
    a = 1ll * a * a;
  } while (b >>= 1);
  return ans;
}
lint qp(int a, ll b, int mo) {
  int ans = 1;
  do {
    if (b & 1)
      ans = 1ll * ans * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return ans;
}
lint gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
long long INF = 1e14;
const int MAX_N = 1 << 17;
const int cf = 100010;
///////////////////////////////////////////////////////////////////////////////
int L[100000];
int main(void) {
  int n, x;
  cin >> n >> x;
  rep(n) cin >> L[i];
  int c = 0;
  int lyn = 0;
  while (lyn <= x) {
    lyn += L[c];
    c++;
    if (c == n + 1)
      break;
  }
  cout << c << endl;
  return 0;
}