Advertisement
a53

politic

a53
Feb 28th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <cstdio>
  2. #define N 20005
  3. using namespace std;
  4. int main()
  5. {
  6. FILE *in=fopen("politic.in","r"),*out=fopen("politic.out","w");
  7. int i,p,u,n,m=1,x,y,v[N],nr;
  8. long sol=0;
  9. fscanf(in,"%d%d",&n,&y);
  10. v[m]=1;
  11. for(i=1;i<n;i++){
  12. fscanf(in,"%d",&x);
  13. if(x-y==1)
  14. v[m]++;
  15. else
  16. v[++m]=1;
  17. y=x;
  18. }
  19.  
  20. p=u=1;
  21. nr=v[1];
  22. while(u<=m){
  23. if(nr>=n/2+1){
  24. sol+=m-u+1;
  25. nr-=v[p];
  26. p++;
  27. }
  28. else
  29. nr+=v[++u];
  30. }
  31. long s=0;
  32. for(i=4936;i<=m;i++)
  33. s+=v[i];
  34. fprintf(out,"%d\n%ld\n",m,sol);
  35. fclose(in);
  36. fclose(out);
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement