#include using namespace std; #define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl #define print(var) std::cout<<#var<<"="<<(var)< #define vvi vector #define vvvi vector #define ll long long #define vll vector #define vvll vector #define vvvll vector #define vmi vector #define vvmi vector #define vvvmi vector #define vs vector #define pii pair #define vpii vector> #define bit(x,i)(((x)>>(i))&1) #define inf (1<<30) #define INF (1ll<<60) template inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } inline double get_time() { using namespace std::chrono; return duration_cast(system_clock::now().time_since_epoch()).count(); } unsigned long xor128(void){ static unsigned long x=123456789,y=362436069,z=521288629,w=88675123; unsigned long t; t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) ); } long long randInt(long long a,long long b){return a+xor128()%(b-a+1);} double randDouble(double a,double b){return a+(b-a)*xor128()/(double)ULONG_MAX;} double start_time; int n,m; vector c(20),l(20); vector> a(20),b(20); bool is_valid(int x,int y){ return 0<=x && x> A; vector bomb; int bomb_sum=0; vector> hist; int building = 0; int shop = 0; ll cost=0; int nowx=0,nowy=0; State(){} State(vector> AA):A(AA){ bomb.resize(m); for(int i=0;i=0 && i=0 && i=INF){ for(int iter=0;iter<5000;iter++){ int i = randInt(0,n-1); int j = randInt(0,n-1); int k = randInt(0,m-1); State state = *this; state.buy(k); state.move(i,j); state.use(k); int broken_building = building - state.building; int broken_shop = shop - state.shop; int usecost = state.cost - cost; ll eval; if(broken_building==0) eval = INF; else if(state.shop==0 && state.building!=0) eval = INF; else{ eval = usecost/broken_building; eval *= max(1,2-state.shop); } if(chmin(best_eval,eval)){ best_state = state; } } } /* for(int i=0;i> A; void IN(){ cin.tie(nullptr); ios::sync_with_stdio(false); cin>>n>>m; A.resize(n); for(int i=0;i>A[i][j]; } } for(int i=0;i>c[i]>>l[i]; for(int j=0;j>tmpa>>tmpb; a[i].emplace_back(tmpa); b[i].emplace_back(tmpb); } } } void solve(){ State state(A); while(state.building>0){ state.one_step(); cerr<