Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <vector>
- using namespace std;
- typedef long long ll;
- typedef pair<int, int> pii;
- #define mp make_pair
- ll w, h;
- ll x, y;
- ll L;
- ll sq;
- int a[1000100];
- vector<pii> ans;
- void print2()
- {
- printf("%d\n", (int)ans.size());
- for (int i = (int)ans.size() - 1; i >= 0; i--)
- printf("%d %d\n", (int)w - ans[i].first, ans[i].second);
- return;
- }
- void solveEasy()
- {
- ans.push_back(mp(1, 0));
- ans.push_back(mp(1, (int)y));
- ans.push_back(mp((int)(x + L), (int)y));
- ans.push_back(mp((int)(x + L), (int)(y + L)));
- ans.push_back(mp((int)x, (int)(y + L)));
- ans.push_back(mp((int)x, (int)(y + 1 + sq / (x - 1) )));
- ans.push_back(mp((int)1 + sq % (x - 1), (int)(y + 1 + sq / (x - 1) )));
- if (sq % (x - 1) != 0)
- {
- ans.push_back(mp(1 + (int)(sq % (x - 1)), (int)(y + 1 + sq / (x - 1) + 1 )));
- ans.push_back(mp(1, (int)(y + 1 + sq / (x - 1) + 1 )));
- }
- ans.push_back(mp(1, h));
- print2();
- return;
- }
- void print()
- {
- int tx = a[0];
- ans.push_back(mp(tx, 0));
- int it = 0;
- while(it < h)
- {
- while (it < h && a[it] == tx) it++;
- ans.push_back(mp(tx, it));
- if (it == h) break;
- tx = a[it];
- ans.push_back(mp(tx, it));
- }
- print2();
- return;
- }
- int main()
- {
- // freopen("input.txt", "r", stdin);
- // freopen("output.txt", "w", stdout);
- cin >> w >> h;
- cin >> x >> y >> L;
- x = w - x - L;
- sq = (w * h) / 2;
- sq -= L * L + h;
- sq -= x - 1LL;
- if (sq < 0)
- {
- printf("Impossible\n");
- return 0;
- }
- if (sq < (x - 1) * (L - 1))
- {
- solveEasy();
- return 0;
- }
- sq -= (x - 1) * (L - 1);
- for (int i = 0; i < h; i++)
- if (i >= y && i < y + L)
- a[i] = x + L;
- else
- a[i] = 1LL;
- for (int i = 0; i < h; i++)
- {
- if (w - 1 - a[i] >= sq)
- {
- a[i] += sq;
- sq = 0;
- break;
- }
- sq -= w - 1 - a[i];
- a[i] = w - 1;
- }
- print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement