|  | 
|  | 
| вернуться в форум | It's fun...I have got AC but... 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...  
 Edited by author 05.11.2011 03:44
Re: It's fun...I have got AC but... 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
 | 
 | 
|