Advertisement
Danlys506

Untitled

May 28th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int a[1010][1010], d[1010][1010];
  6.  
  7. int main()
  8. {
  9. int x, y;
  10. cin >> x >> y;
  11. --y;
  12. for(int i = 0; i < x; ++i)
  13. cin >> a[i][0], --a[i][0];
  14.  
  15. for(int i = 0; i < x; ++i)
  16. cin >> a[i][1], --a[i][1];
  17.  
  18. for(int i = 0; i <= x; ++i)
  19. {
  20. int mx = 400;
  21. for(int j = 0; j < i; ++j)
  22. d[a[j][0]][0] = mx, --mx;
  23.  
  24. mx = x - i;
  25.  
  26. for(int j = i; j < x; ++j)
  27. d[a[j][0]][0] = mx, --mx;
  28.  
  29. for(int j = 0; j <= x; ++j)
  30. {
  31. mx = 400;
  32. for(int k = 0; k < j; ++k)
  33. d[a[k][1]][1] = mx, -mx;
  34.  
  35. mx = x - j;
  36.  
  37. for(int k = j; k < x; ++k)
  38. d[a[k][1]][1] = mx, --mx;
  39.  
  40. int p = 0;
  41. for(int k = 0; k < x; ++k)
  42. if(d[k][0] + d[k][1] - d[0][0] - d[0][1] > 0)
  43. ++p;
  44.  
  45. if(p == y)
  46. {
  47. cout << "Possible" << endl;
  48. for(int q = 0; q < x; ++q)
  49. cout << d[a[q][0]][0] << " ";
  50. cout << endl;
  51. for(int q = 0; q < x; ++q)
  52. cout << d[a[q][1]][1] << " ";
  53. cout << endl;
  54. return 0;
  55. }
  56. }
  57. }
  58. cout << "Impossible\n";
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement