Problem p00560 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>
using namespace std;

long long int n, m, k, a, b, c, t;
vector<long long int> s;
long long int ans;
typedef pair<long long int, long long int> P;
vector<P> v;
vector<long long int> w;
int q[3010];

long long int func(long long int x, long long int y, long long int z) {
  if (y == s[x + 1])
    return 0;
  long long int tmp = t - z;
  if (tmp < 0)
    return 0;
  tmp /= a;
  if (y - 1 + tmp >= s[x + 1])
    tmp = s[x + 1] - y;
  return tmp;
}

int main() {
  scanf("%lld %lld %lld %lld %lld %lld %lld", &n, &m, &k, &a, &b, &c, &t);
  for (int i = 0; i < m; ++i) {
    long long int tmp;
    scanf("%lld", &tmp);
    s.push_back(tmp);
    if ((tmp - 1) * b <= t)
      ++ans;
  }
  s.push_back(n + 1);

  for (int i = 0; i < m; ++i) {
    long long int tmp = func(i, s[i] + 1, (s[i] - 1) * b);
    ans += tmp;
    v.push_back(P(i, s[i] + tmp + 1));
    ++q[i];
  }
  //	printf("%lld\\n", ans);

  //	for(int i=0; i<v.size(); ++i) printf("%lld %lld\\n", v[i].first,
  //v[i].second);

  for (int i = 0; i < v.size(); ++i) {
    if (q[v[i].first] > k)
      continue;
    long long int tmp = 0;
    if ((s[v[i].first] - 1) * b + (v[i].second - s[v[i].first]) * c <= t)
      ++tmp;
    tmp += func(v[i].first, v[i].second + 1,
                (s[v[i].first] - 1) * b + (v[i].second - s[v[i].first]) * c);
    w.push_back(tmp);
    if (tmp > 0) {
      v.push_back(P(v[i].first, v[i].second + tmp));
      ++q[v[i].first];
    }
  }

  sort(w.begin(), w.end(), greater<long long int>());

  //	for(int i=0; i<w.size(); ++i) printf("w%lld\\n", w[i]);

  for (int i = 0; i < min(k - m, (long long int)w.size()); ++i) {
    ans += w[i];
    //		printf("%lld\\n", ans);
  }

  printf("%lld\\n", ans - 1);
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>
using namespace std;

long long int n, m, k, a, b, c, t;
vector<long long int> s;
long long int ans;
typedef pair<long long int, long long int> P;
vector<P> v;
vector<long long int> w;

long long int func(long long int x, long long int y, long long int z) {
  if (y == s[x + 1])
    return 0;
  long long int tmp = t - z;
  if (tmp < 0)
    return 0;
  tmp /= a;
  if (y - 1 + tmp >= s[x + 1])
    tmp = s[x + 1] - y;
  return tmp;
}

int main() {
  scanf("%lld %lld %lld %lld %lld %lld %lld", &n, &m, &k, &a, &b, &c, &t);
  for (int i = 0; i < m; ++i) {
    long long int tmp;
    scanf("%lld", &tmp);
    s.push_back(tmp);
    if ((tmp - 1) * b <= t)
      ++ans;
  }
  s.push_back(n + 1);

  for (int i = 0; i < m; ++i) {
    long long int tmp = func(i, s[i] + 1, (s[i] - 1) * b);
    ans += tmp;
    v.push_back(P(i, s[i] + tmp + 1));
  }
  //	printf("%lld\\n", ans);

  //	for(int i=0; i<v.size(); ++i) printf("%lld %lld\\n", v[i].first,
  //v[i].second);

  for (int i = 0; i < v.size(); ++i) {
    //		if(i == k) break;
    long long int tmp = 0;
    if ((s[v[i].first] - 1) * b + (v[i].second - s[v[i].first]) * c <= t)
      ++tmp;
    tmp += func(v[i].first, v[i].second + 1,
                (s[v[i].first] - 1) * b + (v[i].second - s[v[i].first]) * c);
    w.push_back(tmp);
    if (tmp != 0)
      v.push_back(P(v[i].first, v[i].second + tmp));
  }

  sort(w.begin(), w.end(), greater<long long int>());

  //	for(int i=0; i<w.size(); ++i) printf("w%lld\\n", w[i]);

  for (int i = 0; i < k - m; ++i)
    ans += w[i];

  printf("%lld\\n", ans - 1);
}