#include #include #define MAX 200009 using namespace std; struct s {int first, second;}; int kolaj[MAX], last[MAX], pos[MAX], poc[MAX]; int lastK, i, j, k, m, n, x, y; //int arr[MAX], first[MAX], second[MAX]; struct s arr[MAX]; //pair arr[MAX]; /* bool operator < (int a, int b) { return pos[a] < pos[b]; } */ /* bool operator < (const pair& a, const pair& b) { return a->first < b->first || (a->first == b->first && a->second > b->second); } */ bool operator < (const struct s& a, const struct s& b) { return a.first < b.first || (a.first == b.first && a.second > b.second); } /* bool operator < (const int& a, const int& b) { return first[a] < first[b] || (first[a] == first[b] && second[a] > second[b]); } */ int find(int x, int y, int n) { if (x>=y) { if (last[x] < n) return x; else return -1; } else { if (last[(x+y)/2] > n) return find((x+y)/2 + 1, y, n); else return find(x, (x+y)/2, n); } } int main() { scanf("%d%d", &n, &m); while(n != 0) { for(i=0;isecond; k = find(0, lastK, x); if (k == -1) { k = ++lastK; poc[k] = 0; } if (lastK == m) { ok = false; break; } last[k] = x; kolaj[x] = k+1; poc[k]++; // pos[x] = k+1; } if (ok) { for(i=0;i