Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <bitset>
- #include <cctype>
- #include <cmath>
- #include <complex>
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include <ctime>
- #include <deque>
- #include <fstream>
- #include <iostream>
- #include <list>
- #include <map>
- #include <memory>
- #include <queue>
- #include <set>
- #include <sstream>
- #include <stack>
- #include <string>
- #include <utility>
- #include <vector>
- #include <iomanip>
- using namespace std;
- /*** typedef ***/
- #define MEMSET_INF 127
- #define MEMSET_HALF_INF 63
- #define stream istringstream
- #define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
- #define repl(i,n) for(__typeof(n) i=1; i<=(n); i++)
- #define FOR(i,a,b) for(__typeof(b) i=(a); i<=(b); i++)
- #define INF (1<<30)
- #define PI acos(-1.0)
- #define pb push_back
- #define ppb pop_back
- #define all(x) x.begin(),x.end()
- #define mem(x,y) memset(x,y,sizeof(x))
- #define memsp(x) mem(x,MEMSET_INF)
- #define memdp(x) mem(x,-1)
- #define memca(x) mem(x,0)
- #define eps 1e-9
- #define pii pair<int,int>
- #define pmp make_pair
- #define ft first
- #define sd second
- #define vi vector<int>
- #define vpii vector<pii>
- #define si set<int>
- #define msi map<string , int >
- #define mis map<int , string >
- typedef long long i64;
- typedef unsigned long long ui64;
- /** function **/
- #define SDi(x) sf("%d",&x)
- #define SDl(x) sf("%lld",&x)
- #define SDs(x) sf("%s",x)
- #define SD2(x,y) sf("%d%d",&x,&y)
- #define SD3(x,y,z) sf("%d%d%d",&x,&y,&z)
- #define pf printf
- #define print(x) pf("%d ", x)
- #define println(x) pf("%d\n", x)
- #define sf scanf
- #define READ(f) freopen(f, "r", stdin)
- #define WRITE(f) freopen(f, "w", stdout)
- /** Main Code **/
- #define NTeam 70
- #define NTable 50
- #define Max 200
- struct team {
- int id, member_no;
- team() {}; // empty constructor to satisfy bokachoda compiler
- team(int a, int b) {id = a; member_no = b;}
- bool operator < (const team& a) const {
- return member_no < a.member_no;
- }
- };
- struct table {
- int id, capacity;
- table() {};
- table(int a, int b) {id = a; capacity = b;}
- bool operator < (const table& a) const {
- return capacity > a.capacity;
- }
- }t[NTable + 10];
- priority_queue <team> q;
- map < int, map <int ,int> > track;
- int m, n;
- bool isPossible() {
- int table_remain = n, member;
- team top;
- table t_obj;
- while(!q.empty()) {
- top = q.top(), q.pop();
- member = top.member_no;
- if(member > table_remain) return false;
- rep(i, member) {
- t_obj = t[i];
- t_obj.capacity -= 1;
- track[top.id][i] = t_obj.id;
- t[i] = t_obj; // restore
- if(!t_obj.capacity) table_remain -= 1;
- }
- }
- return true;
- }
- int main() {
- #ifndef ONLINE_JUDGE
- READ("input.txt");
- #endif
- int team_member, capacity, temp[NTeam + 10];
- bool result;
- while(SD2(m, n) && n && m) {
- q = priority_queue <team> ();
- rep(i, m) SDi(team_member), temp[i] = team_member, q.push(team(i, team_member));
- rep(i, n) SDi(capacity), t[i] = table(i, capacity);
- sort(t, t + n);
- result = isPossible();
- println(result);
- if(result) {
- rep(i, m) {
- int arr[Max];
- rep(j, temp[i]) arr[j] = track[i][j] + 1;
- sort(arr, arr + temp[i]);
- rep(j, temp[i]) pf("%d ", arr[j]);
- pf("\n");
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement