Advertisement
Guest User

cpp_chief_hopper

a guest
Nov 21st, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <queue>
  7. using namespace std;
  8.  
  9.  
  10. int main() {
  11.     // insert code here...
  12.     queue<int> overflow;
  13.     int T, stkCnt=0;
  14.     cin >> T;
  15.     int A[100000];
  16.     int max = 0;
  17.     for(int i=0; i<T; i++){
  18.         cin >> A[i];
  19.         //A[i] = 2;
  20.         if(A[i]>max)
  21.             max = A[i];
  22.     }
  23.     //A[20]=1;
  24.     long long int e=0;
  25.     for(int n=0;n<=max;n++){
  26.         e = n;
  27.         int i=0;
  28.         while(i < T ){
  29.             e = 2*e - A[i];
  30.             if(stkCnt > 0){
  31.                 overflow.push(2);
  32.                 for(int i=0; i< stkCnt ;i++){
  33.                     do{
  34.                         int num = overflow.front();
  35.                         overflow.pop();
  36.                         overflow.push(num);
  37.                     }while(overflow.front() == 2);
  38.                     overflow.push(2);
  39.                 }
  40.             }
  41.             if(e > 1000000000){
  42.                 overflow.push(999900000);
  43.                 e = e - 999900000;
  44.                 stkCnt++;
  45.             }
  46.             int num = 1;
  47.             if(e < 0 && stkCnt > 0){
  48.                 do{
  49.                     num = num * overflow.front();
  50.                     overflow.pop();
  51.                 }while(overflow.front()==2);
  52.                 e = e + num;
  53.             }
  54.             if(e<0) break;
  55.             i++;
  56.         }
  57.         if(i == T){
  58.             e = n;
  59.             break;
  60.         }
  61.     }
  62.     cout << e << endl;
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement