denis_andrei10

pasda

Feb 11th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int v[100001];
  4. int main()
  5. {
  6. int i, maj, ap, n;
  7. cin>>n;
  8. cin>>v[1];
  9. maj=v[1];
  10. ap=1;
  11. for(i=2; i<=n; i++)
  12. {
  13. cin>>v[i];
  14. if(v[i]==maj)
  15. {
  16. ap++;
  17. }
  18. else
  19. {
  20. ap--;
  21. if(ap==0)
  22. {
  23. ap=1;
  24. maj=v[i];
  25. }
  26. }
  27. }
  28. ap=0;
  29. for(i=1; i<=n; i++)
  30. {
  31. if(v[i]==maj)
  32. {
  33. ap++;
  34. }
  35. }
  36. if(ap>n/2)
  37. {
  38. cout<<"DA"<<' '<<maj;
  39. }
  40. else
  41. {
  42. cout<<"NU";
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment