Time Lapse :NONE 9280.cpp1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889#include<iostream>#include <vector>#include <algorithm>#include <memory.h>using namespace std;int N,M;vector<int> answer;vector<int> fee;vector<int> weight;vector<int> inout;int is_full[100];int place[2001];bool get_in(int num){ for (int j = 0; j < N; j++) { if (is_full[j]==0) { answer[answer.size()-1] += weight[num-1]*fee[j]; is_full[j] = num; place[num]=j; inout.erase(inout.begin()); return true; } } return false;}void test(){ fee.clear(); weight.clear(); inout.clear(); fee.resize(N); weight.resize(M); inout.resize(2*M); memset(is_full,0,sizeof(is_full)); answer.push_back(0); for(int i=0;i<N;i++) cin>>fee[i]; for(int i=0;i<M;i++) cin>>weight[i]; for(int i=0;i<2*M;i++) cin>>inout[i]; int use = 0; while(inout.size()!=0) { if (use < N) { int num = inout[0]; if (num > 0) { get_in(num); ++use; } else { is_full[place[num*-1]]=0; --use; inout.erase(inout.begin()); } } else{ for(int i=0;i<inout.size()-1;i++){ if(inout[i]<0){ is_full[place[inout[i]*-1]] = 0; inout.erase(inout.begin()+i); --use; break; } } } }}int main(int argc, char** argv){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int test_case; int T; cin>>T; for(test_case = 1; test_case <= T; ++test_case) { cin>>N>>M; test(); } for(int i=0;i<answer.size();i++) cout<<"#"<<i+1<<" "<<answer[i]<<endl; return 0;//정상종료시 반드시 0을 리턴해야합니다.}