alexjercan/bugnet huggingface dataset:
Problem p00034 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

int main(void) {
  double line[10];
  double v1, v2;

  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &line[0],
               &line[1], &line[2], &line[3], &line[4], &line[5], &line[6],
               &line[7], &line[8], &line[9], &v1, &v2) != EOF) {

    double sum = 0;

    for (int i = 0; i < 10; i++) {
      sum += line[i];
    }

    double time = sum / (v1 + v2);

    double dist = time * v1;

    for (int i = 0; i < 10; i++) {
      dist -= line[i];

      if (dist <= 0) {
        cout << i + 1 << endl;
        break;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int main(void) {
  double line[10];
  double v1, v2;

  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &line[0],
               &line[1], &line[2], &line[3], &line[4], &line[5], &line[6],
               &line[7], &line[8], &line[9], &v1, &v2)) {

    double sum = 0;

    for (int i = 0; i < 10; i++) {
      sum += line[i];
    }

    double time = sum / (v1 + v2);

    double dist = time * v1;

    for (int i = 0; i < 10; i++) {
      dist -= line[i];

      if (dist <= 0) {
        cout << i + 1 << endl;
        break;
      }
    }
  }

  return 0;
}
Problem p00034 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int data[11];
int sum = 0;
bool input() {
  fill(data, data + 11, 0);
  char c;
  int x;
  for (int i = 1; i <= 10; i++) {
    if (!(cin >> x))
      return false;
    cin >> c;
    data[i] = data[i - 1] + x;
  }
  return true;
}
int main() {
  while (input()) {
    int v1, v2;
    char c;
    cin >> v1 >> c >> v2;
    double t = 1. * data[10] / (v1 + v2);

    for (int i = 1; i <= 10; i++) {
      if (v1 * t <= data[i]) {
        cout << i << endl;
        break;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int data[11];
int sum = 0;
bool input() {
  fill(data, data + 11, 0);
  char c;
  int x;
  for (int i = 1; i <= 10; i++) {
    cin >> x;
    cin >> c;
    data[i] = data[i - 1] + x;
  }
  return true;
}
int main() {
  while (input()) {
    int v1, v2;
    char c;
    cin >> v1 >> c >> v2;
    double t = 1. * data[10] / (v1 + v2);

    for (int i = 1; i <= 10; i++) {
      if (v1 * t <= data[i]) {
        cout << i << endl;
        break;
      }
    }
  }
}
Problem p00034 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <ctype.h>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
  double b[10];
  double v1, v2;

  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &b[0], &b[1],
               &b[2], &b[3], &b[4], &b[5], &b[6], &b[7], &b[8], &b[9], &v1,
               &v2) != EOF) {
    double l =
        b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6] + b[7] + b[8] + b[9];
    double t = l / (v1 + v2);
    double l1 = t * v1;
    for (int i = 0; i < 10; i++) {
      l1 -= b[i];
      if (l1 <= 0) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <ctype.h>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
  double b[10];
  double v1, v2;

  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &b[0], &b[1],
               &b[2], &b[3], &b[4], &b[5], &b[6], &b[7], &b[8], &b[9], &v1,
               &v2)) {
    double l =
        b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6] + b[7] + b[8] + b[9];
    double t = l / (v1 + v2);
    double l1 = t * v1;
    for (int i = 0; i < 10; i++) {
      l1 -= b[i];
      if (l1 <= 0) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p00034 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
  int ta[10], v1, v2;
  char xx;
  while (true) {
    int sum = 0;
    for (int i = 0; i < 10; i++) {
      cin >> ta[i] >> xx;
      sum += ta[i];
    }
    if (!(cin >> v1 >> xx >> v2))
      break;
    double t = 0.0;
    for (;; t += 0.001) {
      if (v1 * t + v2 * t >= sum)
        break;
    }
    int ans = 0;
    double tsum = 0.0;
    for (int i = 0; i < 10; i++) {
      if (tsum > v1 * t)
        break;
      if (t * v1 - tsum <= 0.00001) {
        break;
      }
      tsum += ta[i];
      ans++;
    }
    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int stoi(string x) {
  stringstream ss;
  ss << x;
  int tmp;
  ss >> tmp;
  return tmp;
}
string itos(int x) {
  stringstream ss;
  ss << x;
  return ss.str();
}
const int INF = 1111111111;
int main() {

  int ta[10], v1, v2, sum = 0;
  double t, n1, n2;
  while (true) {
    for (int i = 0; i < 10; i++) {
      cin >> ta[i];
      cin.ignore();
      sum += ta[i];
    }
    char tmp;
    if (!(cin >> v1 >> tmp >> v2))
      break;
    for (double i = 0.0;; i += 0.01) {
      n1 = v1 * i, n2 = sum - v2 * i;
      if (abs(n1 - n2) <= 0.01) {
        t = i;
        break;
      }
    }
    sum = 0;
    for (int i = 0; i < 10; i++) {
      ;
      if (v1 * t < (double)sum) {
        cout << i << endl;
        break;
      }
      sum += ta[i];
    }
  }
  return 0;
}
Problem p00034 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <stdio.h>
using namespace std;

int pow(int a, int n) {
  if (n <= 0) {
    return 1;
  }
  return a * pow(a, n - 1);
}

int main() {
  int v1, v2;
  int a[10];
  int sum1;
  int sum2;
  int ans = 0;
  while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &a[0], &a[1], &a[2],
               &a[3], &a[4], &a[5], &a[6], &a[7], &a[8], &a[9], &v1,
               &v2) != EOF) {
    sum1 = 0;
    sum2 = 0;
    for (int i = 0; i < 10; i++) {
      sum1 += a[i];
    }
    for (int i = 0; i < 10; i++) {
      sum2 += a[i];
      if (sum1 * v1 > sum2 * (v1 + v2)) {
        ans = i + 2;
      }
    }
    printf("%d\\n", ans);
  }
  ///////////////////////////////////
  // Sleep(200000);///////////////////// 提出するときは必ず外す！
  ///////////////////////////////////
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <stdio.h>
using namespace std;

int pow(int a, int n) {
  if (n <= 0) {
    return 1;
  }
  return a * pow(a, n - 1);
}

int main() {
  int v1, v2;
  int a[10];
  int sum1;
  int sum2;
  int ans = 0;
  while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &a[0], &a[1], &a[2],
               &a[3], &a[4], &a[5], &a[6], &a[7], &a[8], &a[9], &v1,
               &v2) != 0) {
    sum1 = 0;
    sum2 = 0;
    for (int i = 0; i < 10; i++) {
      sum1 += a[i];
    }
    for (int i = 0; i < 10; i++) {
      sum2 += a[i];
      if (sum1 * v1 > sum2 * (v1 + v2)) {
        ans = i + 2;
      }
    }
    printf("%d\\n", ans);
  }
  ///////////////////////////////////
  // Sleep(200000);///////////////////// 提出するときは必ず外す！
  ///////////////////////////////////
  return 0;
}
Problem p00034 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define PI acos(-1.0)
#define ALL(A) ((A).begin(), (A).end())
#define vsort(v) sort(v.begin(), v.end())
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)

int main() {
  double v1, v2, l[10];
  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &l[0], &l[1],
               &l[2], &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1,
               &v2) != EOF) {

    double p[11];
    p[0] = 0;
    FOR(i, 1, 11) { p[i] = p[i - 1] + l[i - 1]; }
    FOR(i, 0, 10) {
      double vt = (p[10] * v1) / (v1 + v2);
      if (p[i] < vt && p[i + 1] >= vt) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define PI acos(-1.0)
#define ALL(A) ((A).begin(), (A).end())
#define vsort(v) sort(v.begin(), v.end())
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)

int main() {
  double v1, v2, l[10];
  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &l[0], &l[1],
               &l[2], &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1,
               &v2)) {

    double p[11];
    p[0] = 0;
    FOR(i, 1, 11) { p[i] = p[i - 1] + l[i - 1]; }
    FOR(i, 0, 10) {
      double vt = (p[10] * v1) / (v1 + v2);
      if (p[i] < vt && p[i + 1] >= vt) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
}
Problem p00034 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int i, sum_len, v[2];
  float closs, l[11], t[2][12] = {};
  while (scanf("%f,", &l[1]) != EOF) {
    sum_len = l[1];
    for (i = 2; i < 11; i++) {
      scanf("%f,", &l[i]);
      sum_len += l[i];
    }
    scanf("%d,%d", &v[0], &v[1]);
    closs = 1.0 * sum_len / (v[0] + v[1]);
    double sum_time[2] = {};
    for (i = 1; i < 10; i++) {
      t[0][i] = sum_time[0] + (l[i] / v[0]);
      t[1][10 - i] = sum_time[1] + l[10 - i] / v[1];
      sum_time[0] += l[i] / v[0];
      sum_time[1] += l[10 - i] / v[1];
    }
    sum_time[0] += l[i] / v[0];
    //    sum_time[1]+=l[10-i]/v[1];
    t[0][10] = t[1][0] = sum_time[0];
    for (i = 0; i < 11; i++) {
      //      cout<<' '<<closs<<t[0][i] << ' ' <<t[1][i]<<endl;
      if (t[0][i] >= closs && t[1][i] <= closs) {
        cout << i << endl;
        break;
      }
      // if(t[0][i] == closs && t[1][i] == closs) {cout<<i-1<<endl; break;}
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int i;
  double closs, l[10], v[2], sum_len = 0.0;
  double sum_time[2] = {};
  double t[2][10] = {};
  while (scanf("%lf,", &l[0])) {
    sum_len = l[0];
    for (i = 1; i < 10; i++) {
      scanf("%lf,", &l[i]);
      sum_len += l[i];
    }
    scanf("%lf,%lf", &v[0], &v[1]);
    closs = 1.0 * sum_len / (1.0 * (v[0] + v[1]));
    sum_time[0] = 0.0;
    sum_time[1] = 0.0;
    for (i = 0; i < 10; i++) {
      t[0][i] = sum_time[0] + (l[i] / v[0]);
      t[1][9 - i] = sum_time[1] + l[9 - i] / v[1];
      sum_time[0] += l[i] / v[0];
      sum_time[1] += l[9 - i] / v[1];
      // cout<<l[i]/v[0] <<' ';
    }
    for (i = 0; i < 10; i++) {
      // cout<<t[0][i] << ' ' <<t[1][i] <<endl;
      if (t[0][i] >= closs && t[1][i] <= closs) {
        cout << i << endl;
        break;
      }
      // if(t[0][i] == t[1][i] && t[0][i] == closs) {cout<<i+1<<endl; break;}
    }
  }
  return 0;
}
Problem p00034 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int dis[10], v1, v2;
  while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &dis[0], &dis[1], &dis[2],
               &dis[3], &dis[4], &dis[5], &dis[6], &dis[7], &dis[8], &dis[9],
               &v1, &v2) != EOF) {
    int sum = 0;
    for (int i = 0; i < 10; i++)
      sum += dis[i];
    double col = (double)sum * (double)v1 / (double)(v1 + v2);
    // cout<<"col:"<<col<<endl;
    sum = 0;
    for (int i = 0; i < 10; i++) {
      sum += dis[i];
      if ((double)sum - col >= -0.000000001) {
        sum = i;
        break;
      }
    }
    cout << sum + 1 << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int dis[10], v1, v2;
  while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &dis[0], &dis[1], &dis[2],
               &dis[3], &dis[4], &dis[5], &dis[6], &dis[7], &dis[8], &dis[9],
               &v1, &v2)) {
    int sum = 0;
    for (int i = 0; i < 10; i++)
      sum += dis[i];
    double col = (double)sum * (double)v1 / (double)(v1 + v2);
    // cout<<"col:"<<col<<endl;
    sum = 0;
    for (int i = 0; i < 10; i++) {
      sum += dis[i];
      if ((double)sum - col >= -0.000000001) {
        sum = i;
        break;
      }
    }
    cout << sum + 1 << endl;
  }
  return 0;
}
Problem p00034 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int a[10];
  int b, c;
  while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &a[0], &a[1], &a[2],
               &a[3], &a[4], &a[5], &a[6], &a[7], &a[8], &a[9], &b, &c) +
         1) {
    int dis = 0;
    for (int i = 0; i < 10; i++) {
      dis += a[i];
    }
    double disa;
    disa = static_cast<double>(dis);
    int speed = b + c;
    double x = disa / speed * b;
    int y = static_cast<int>(x);
    int j = 0;
    while (1) {
      if (y - a[j] <= 0) {
        break;
      }
      y -= a[j];
      j++;
    }
    cout << j + 1 << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int ar[12];
  int dis = 0;
  int speed;
  int x = 0;
  while (1) {
    for (int i = 0; i < 12; i++) {
      scanf("%d,", &ar[i]);
    }
    if (ar[0] == EOF) {
      break;
    }
    for (int i = 0; i < 10; i++) {
      dis += ar[i];
    }
    int speed = ar[10] + ar[11];
    int a = (dis + speed - 1) / speed;
    while (1) {
      if (a - ar[x] < 0) {
        break;
      }
      a -= ar[x];
      x++;
    }
    cout << x << endl;
  }
  return 0;
}
Problem p00034 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int v1, v2, ret;
  double sum = 0;
  vector<int> l(10, 0);
  while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &l[0], &l[1], &l[2],
               &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1,
               &v2) != EOF) {
    sum = 0;
    for (int i = 0; i < 10; i++) {
      sum += l[i];
    }
    sum /= (v1 + v2);
    sum *= v1;
    for (int i = 0; i < 10; i++) {
      sum -= l[i];
      if (sum <= 0) {
        ret = i + 1;
        break;
      }
    }
    cout << ret << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int v1, v2, sum, ret;
  vector<int> l(10, 0);
  for (int c = 0; c < 2000000; c++) {
    scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\\n", &l[1], &l[2], &l[3], &l[4],
          &l[5], &l[6], &l[7], &l[8], &l[9], &l[10], &v1, &v2);
    sum =
        (l[1] + l[2] + l[3] + l[4] + l[5] + l[6] + l[7] + l[8] + l[9] + l[10]) *
        (int)(v1 / (v1 + v2));
    for (int i = 0; i < 10; i++) {
      sum -= l[i];
      if (sum <= 0) {
        ret = i;
        break;
      }
    }
    cout << ret << endl;
  }
  return 0;
}
Problem p00034 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {

  int num[11] = {};
  int x, t, T = 0;
  double S1 = 0, S2 = 0, V1, V2, W;
  bool f1 = false, f2 = false;
  while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%lf,%lf", &num[0], &num[1],
               &num[2], &num[3], &num[4], &num[5], &num[6], &num[7], &num[8],
               &num[9], &V1, &V2) != EOF) {
    /*
    for(int i=1;i<10;i++)
    {scanf("%d",&x);num[i]=x;}
    cin>>V1>>V2;
    */
    W = 0;
    S1 = 0;
    S2 = 0;
    for (int i = 0; i < 10; i++)
      S1 += num[i];
    for (int i = 0; i < 10; i++)
      S2 = V1 + V2;
    t = 0;
    T = 0;
    W = S1 * V1 / S2;
    // cout<<S1<<" "<<S2<<" "<<W<<" ";
    do {

      T += num[t];
      if (T == W)
        f1 = true;
      t++;
    } while (T < W);
    if (f1 == false)
      printf("%d\\n", t);
    else if (f1 == true)
      printf("%d\\n", t);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {

  int num[11] = {};
  int x, t, T = 0;
  double S1 = 0, S2 = 0, V1, V2, W;
  bool f1 = false, f2 = false;
  while (scanf("%d %d %d %d %d %d %d %d %d %d %lf %lf", &num[0], &num[1],
               &num[2], &num[3], &num[4], &num[5], &num[6], &num[7], &num[8],
               &num[9], &V1, &V2) != EOF) {
    /*
    for(int i=1;i<10;i++)
    {scanf("%d",&x);num[i]=x;}
    cin>>V1>>V2;
    */
    for (int i = 0; i < 10; i++)
      S1 += num[i];
    for (int i = 0; i < 10; i++)
      S2 = V1 + V2;
    t = 0;
    W = S1 * V1 / S2;

    do {

      T += num[t];
      if (T == W)
        f1 = true;
      t++;
    } while (T < W);
    if (f1 == false)
      printf("%d\\n", t);
    else if (f1 == true)
      printf("%d\\n", t);
  }
  return 0;
}
Problem p00034 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;

int main() {
  int l[10], v1, v2, cnt;
  double n, d, t;
  char ch;
  while (cin >> l[0] >> ch) {
    n = l[0];
    for (int i = 1; i < 10; i++) {
      cin >> l[i] >> ch;
      n += l[i];
    }
    cin >> v1 >> ch >> v2;
    t = n / (v1 + v2);
    d = v1 * t; // 列車1の動く距離
    cnt = 0;
    while (d > 0) {
      d -= l[cnt];
      cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

int main() {
  int l[10], v1, v2, n, m;
  double d, t;
  while (1) {
    for (int i = 0; i < 10; i++) {
      cin >> l[i];
    }
    cin >> v1 >> v2;
    t = n / (v1 + v2);
    d = v1 * t; // 列車1の動く距離
    m = 0;
    for (int i = 0; i < 10; i++) {
      m += l[i];
      if (m < d) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p00034 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<int> v(10);
  int sp1, sp2;
  char k;

  while (cin >> v[0]) {
    double all = v[0];
    for (int i = 1; i < 10; i++) {
      cin >> k >> v[i];
      all += v[i];
    }
    cin >> k >> sp1 >> k >> sp2;

    double hour = all / (sp1 + sp2);
    double len = sp1 * hour;

    int k = 0;
    while (len > 0) {
      len -= (double)v[k];
      k++;
    }

    cout << k << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<int> v(10);
  int sp1, sp2;
  double all = 0;
  char k;

  while (cin >> v.at(0)) {
    for (int i = 1; i < 10; i++) {
      cin >> k >> v.at(i);
    }
    cin >> k >> sp1 >> k >> sp2;

    for (int i = 0; i < 10; i++) {
      all += v.at(i);
    }

    double hour = all / (sp1 + sp2);
    double len = sp1 * hour;

    int k = 0;
    while (len > 0) {
      len -= (double)v.at(k);
      k++;
    }

    cout << k << endl;
  }

  return 0;
}
Problem p00034 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
#include <vector>
int main() {
  int v1, v2;
  std::vector<int> vec(10);
  while (scanf("%d,", &vec[0]) != EOF) {
    float sum = 0;
    for (int i = 1; i < 10; i++) {
      scanf("%d,", &vec[i]);
      // std::cin>>vec[i];
      sum += vec[i];
    }
    scanf("%d,%d", &v1, &v2);
    // std::cin>>v1>>v2;
    if (std::cin.eof())
      break;
    float time = sum / (v1 + v2);
    float a = v1 * time;
    int b = 0;
    while (a > 0) {
      a -= vec[b];
      b++;
    }
    std::cout << b << std::endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <vector>
int main() {
  int v1, v2;
  std::vector<int> vec(10);
  while (1) {
    float sum = 0;
    for (int i = 0; i < 10; i++) {
      scanf("%d,", &vec[i]);
      // std::cin>>vec[i];
      sum += vec[i];
    }
    scanf("%d,%d", &v1, &v2);
    // std::cin>>v1>>v2;
    if (std::cin.eof())
      break;
    float time = sum / (v1 + v2);
    float a = v1 * time;
    int b = 0;
    while (a > 0) {
      a -= vec[b];
      b++;
    }
    std::cout << b << std::endl;
  }
  return 0;
}
Problem p00034 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>

int main() {
  const int MAX = 10;
  int l[MAX];
  int v1, v2;
  int sumL;

  while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &l[0], &l[1], &l[2],
               &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1,
               &v2) != EOF) {
    sumL = 0;
    for (int i = 0; i < MAX; i++) {
      sumL += l[i];
    }
    float l1 = v1 * ((float)sumL / (v1 + v2));
    for (int i = 0; i < MAX; i++) {
      l1 -= l[i];
      if (l1 <= 0.0) {
        printf("%d\\n", i + 1);
        break;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>

int main() {
  const int MAX = 10;
  int l[MAX];
  int v1, v2;
  int sumL;

  while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &l[0], &l[1], &l[2],
               &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1,
               &v2) != EOF) {
    sumL = 0;
    for (int i : l) {
      sumL += i;
    }
    float l1 = v1 * ((float)sumL / (v1 + v2));
    int ans = 0;
    while (l1 > 0.0) {
      l1 -= l[ans++];
    }
    printf("%d\\n", ans);
  }

  return 0;
}
Problem p00035 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>

using namespace std;

bool check(double X1, double Y1, double X2, double Y2, double X3, double Y3,
           double X4, double Y4) {
  return ((X1 - X2) * (Y3 - Y1) - (Y1 - Y2) * (X3 - X1)) *
             ((X1 - X2) * (Y4 - Y1) - (Y1 - Y2) * (X4 - X1)) >
         0.0;
}

void solve() {
  double xa, ya, xb, yb, xc, yc, xd, yd;
  while (~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc,
                &xd, &yd))
    if (check(xa, ya, xc, yc, xb, yb, xd, yd) ||
        check(xb, yb, xd, yd, xa, ya, xc, yc)) {
      cout << "NO" << endl;
    } else {
      cout << "YES" << endl;
    }
}

int main() {
  solve();
  return (0);
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>

using namespace std;

bool check(double X1, double Y1, double X2, double Y2, double X3, double Y3,
           double X4, double Y4) {
  return ((X1 - X2) * (Y3 - Y1) - (Y1 - Y2) * (X3 - X1)) *
             ((X1 - X2) * (Y4 - Y1) - (Y1 - Y2) * (X4 - X1)) >
         0.0;
}

void solve() {
  double xa, ya, xb, yb, xc, yc, xd, yd;
  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc,
               &xd, &yd))
    if (check(xa, ya, xc, yc, xb, yb, xd, yd) ||
        check(xb, yb, xd, yd, xa, ya, xc, yc)) {
      cout << "NO" << endl;
    } else {
      cout << "YES" << endl;
    }
}

int main() {
  solve();
  return (0);
}