pang
#include <iostream> #include <fstream> #include <string> #include <algorithm> #include "math.h" #include <stack> #define MAXN 300 using namespace std; int input[MAXN*2]; stack<int> m_stack; int main(){ int N(0),K(0); cin>>N>>K; for(int i=0;i<N+K;i++){ cin>>input[i]; } int count(0); int iter(0); int temp = input[iter]; count++; while(count<N){ if(temp==input[count]){ input[iter]++; input[count]=-1; if(iter>0){ iter--;} while(iter>0&&input[iter]==-1) iter--; temp = input[iter]; count--; while(input[count]==-1) count--; if(count==iter){ count++; while(input[count]==-1){ count++; } } N++; } else{ iter++; count++; while(input[iter]==-1) iter++; while(input[count]==-1) count++; temp = input[iter]; } } int max=0; for(int i=0;i<N;i++){ if(input[i]>max) max = input[i]; } cout<<"max is "<<max<<endl; system("pause"); return 0; }