Блог пользователя Quenenty

Автор Quenenty, история, 6 лет назад, По-английски

Hello everyone, so I'm working on tram problem (link : https://codeforces.me/contest/116/problem/A)

and while I use this code, i got 6 as the answer (a correct answer), but when i submit it to codeforces, i got 2001467757 as the output.. Can anyone help me point out why?

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

using namespace std;

int main() {
    int busStop, minSeat[1000], counter = 0, a[1000], b[1000];
    minSeat[0] = 0;
    cin >> busStop;
    for (int i = 0; i < busStop; i ++ )
    {
       cin >> a[i] >> b[i];
       counter = counter - a[i] + b[i];
       minSeat[i] = counter;

    }

    for (int i = 0; i < 1000; i++)
    {
       if (minSeat[0] < minSeat[i])
       {
         minSeat[0] = minSeat[i];
       }
    }
    cout << endl << minSeat[0];
}
  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Variables, arrays inside any functions are not guaranteed to be zero under -O2 optimisation. As a result, it's necessary to manually assign value for them

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

You can check it with this code:

Code