ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1787. Turn for MEGA

Complication error? In Dev it works...
Posted by Greg Mice 11 Jul 2012 19:09
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int a;
    cin>>a;
    int b;
    cin>>b;
    int c;
    int tab[b];
    for(int i=0; i<b; i++)
    {
            cin>>tab[i];
            }
    for (int j=1; j<b; j++)
    {
        if (tab[j-1]-a<0) tab[j]=tab[j];
        else tab[j]=tab[j]+(tab[j-1]-a);

        }
    if (tab[b-1]-a<0) cout<<"0"<<endl;
    else cout<<(tab[b-1]-a)<<endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}

In dev-c++ it works...

Edited by author 11.07.2012 19:10
Re: Complication error? In Dev it works...
Posted by Andrew Sboev 11 Jul 2012 19:14
Error in this line
int tab[b];
Array size should be constant value.
Re: Complication error? In Dev it works...
Posted by Templar555 12 Jul 2012 13:50
The problem is that compiler on this website(Visual C++) has a little another syntax and you can't use such thing:
int b;
cin>>b;
int tab[b];
An array size in C++ must be initialized by a constant value, so you can't initialize it by a variable you read from the stream. Try use dynamic arrays in such cases.

Edited by author 12.07.2012 13:50