#include #include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) template bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T &x, T y) { return x < y ? (x = y, true) : false; } struct io_setup { io_setup() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(15); } } io_setup; int main(){ int n,m; cin>>n>>m; vector e(n); rep(i,0,n) cin>>e.at(i); vector> vw(m); for(auto&[v,w]:vw) cin>>v>>w; ll mx=0; vector> ans(n); rep(bit,1,(1<>i)&1) tmp+=vw.at(i).first; if(tmp> nw; rep(i,0,m) if((bit>>i)&1) nw.push_back({vw.at(i).second,i}); sort(nw.begin(),nw.end()); auto ce=e; vector> nans(n); int flg=0; while(!nw.empty()){ auto[x,i]=nw.back(); nw.pop_back(); int j=-1,d=1e9; rep(k,0,n) if(ce.at(k)>=x){ if(chmin(d,ce.at(k)-x)) j=k; } if(j==-1){ flg=1; break; } ce.at(j)-=x; nans.at(j).push_back(i); } if(!flg) swap(ans,nans),mx=tmp; } cout<