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 1120. Sum of Sequential Numbers

Crash #9
Posted by Alisher 5 Jun 2011 21:09
Could someone explain me why I've got Crash #9?
I was trying all tests here but I've got nothing.

#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

int n, a[111111], b[111111], i, l = 0, sum, index = 1;

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    cin >> n;

    for(i=1;i<=100000;i++) {
        a[i] = a[i-1] + i;
    }

    while(true) {
        sum = a[index] - a[l] + l;
        if(sum == n) {
            int e = index - l + 1;
            if(l == 0)    l++, e--;
            cout << l << " " << e;
            return 0;
        }
        if(sum > n) {
            l++;
        }
        else {
            index++;
        }
    }

    return 0;
}

Edited by author 05.06.2011 21:10