Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- #include <queue>
- using namespace std;
- int main() {
- // insert code here...
- queue<int> overflow;
- int T, stkCnt=0;
- cin >> T;
- int A[100000];
- int max = 0;
- for(int i=0; i<T; i++){
- cin >> A[i];
- //A[i] = 2;
- if(A[i]>max)
- max = A[i];
- }
- //A[20]=1;
- long long int e=0;
- for(int n=0;n<=max;n++){
- e = n;
- int i=0;
- while(i < T ){
- e = 2*e - A[i];
- if(stkCnt > 0){
- overflow.push(2);
- for(int i=0; i< stkCnt ;i++){
- do{
- int num = overflow.front();
- overflow.pop();
- overflow.push(num);
- }while(overflow.front() == 2);
- overflow.push(2);
- }
- }
- if(e > 1000000000){
- overflow.push(999900000);
- e = e - 999900000;
- stkCnt++;
- }
- int num = 1;
- if(e < 0 && stkCnt > 0){
- do{
- num = num * overflow.front();
- overflow.pop();
- }while(overflow.front()==2);
- e = e + num;
- }
- if(e<0) break;
- i++;
- }
- if(i == T){
- e = n;
- break;
- }
- }
- cout << e << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement