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 1126. Magnetic Storms

It's fun...I have got AC but...
Posted by vilvler 5 Nov 2011 02:37
Here my solution. In c[x] I store how much I have elements with key x in set. So it is in this range M ≤ N ≤ 25000. But when I set size of c to 25000 I have got Crash on 4 test. What is wrong in my solution?
#include <stdio.h>
#include <vector>
#include <set>
#include <stdlib.h>
#include <algorithm>


int main(){
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    int m,b,c[200000],l,r,d;
    std::vector <int> a;
    std::set <int> set;
    std::set <int>::iterator it;
    memset(c,0,sizeof(c));
    scanf("%d",&m);
    scanf("%d",&b);
    while (b!=-1){
        a.push_back(b);
        scanf("%d",&b);
    }
    d=a.size();
    for (int i=0; i<std::min(m,d); i++){
        set.insert(a[i]);
        c[a[i]]++;
    }
    if (m-1<d && m!=0){
        l=0; r=m-1;
        while (r<d-1){
            it=set.end();
            it--;
            printf("%d\n",*it);
            r++;
            c[a[r]]++;
            set.insert(a[r]);
            c[a[l]]--;
            if (c[a[l]]==0) set.erase(a[l]);
            l++;
        }
    }
    if (set.size()>0){
        it=set.end();
        it--;
        printf("%d\n",*it);
    }else{printf("0");}
//    fclose(stdin); fclose(stdout);
}
Re: It's fun...I have got AC but...
Posted by Macarie 5 Nov 2011 03:44


Edited by author 05.11.2011 03:44
Re: It's fun...I have got AC but...
Posted by morbidel 5 Nov 2011 03:45
Hello,
as far as I see, you index C with values from A, which can contain numbers from 0 to 100000.

Edited by author 05.11.2011 23:20