Advertisement
Guest User

pesci

a guest
Jun 13th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <cstdio>
  2. #include <stack>
  3. using namespace std;
  4.  
  5. int N;
  6. stack<int> zero, uno;
  7.  
  8. int funny() {
  9.     if(!zero.empty() && !uno.empty()) {
  10.         while(!zero.empty() && !uno.empty()) {
  11.             int z = zero.top();
  12.             int u = uno.top();
  13.             if(z > u) uno.pop();
  14.             else zero.pop();
  15.         }
  16.         return (zero.size() + uno.size());
  17.     }
  18.     return N;
  19. }
  20.  
  21. int main() {
  22.     freopen("input.txt", "r", stdin);
  23.     freopen("output.txt", "w", stdout);
  24.     scanf("%d", &N);
  25.     for(int i = 0, direzione, dimensione; i < N; i++) {
  26.         scanf("%d%d", &direzione, &dimensione);
  27.         if(direzione == 0) zero.push(dimensione);
  28.         else uno.push(dimensione);
  29.     }
  30.     printf("%d", funny());
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement