Advertisement
a53

LeMans

a53
Jun 2nd, 2021
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include <algorithm>
  2. #include <stdio.h>
  3.  
  4. #define MaxN 1005
  5. #define INF (1LL << 60)
  6.  
  7. using namespace std;
  8.  
  9. FILE *file_in = fopen("lemans.in", "r");
  10. FILE *file_out = fopen("lemans.out", "w");
  11.  
  12. int N, M, T, L, fr[MaxN], v[MaxN], p[MaxN], out[MaxN];
  13. int active, left = 1, right, best_left, best_right;
  14. long long ans = INF;
  15. pair<long long, pair<int, int>> pos[MaxN * MaxN];
  16.  
  17. int main() {
  18.  
  19. fscanf(file_in, "%d %d %d", &T, &N, &M);
  20.  
  21. for (int i = 1; i <= N; i++) {
  22. fscanf(file_in, "%d", &v[i]);
  23. }
  24.  
  25. for (int i = 1; i <= M; i++) {
  26. fscanf(file_in, "%d", &p[i]);
  27. }
  28.  
  29. for (int i = 1; i <= N; i++) {
  30. for (int j = 1; j <= M; j++) {
  31. pos[++L] = make_pair(1LL * T * v[i] + p[j], make_pair(i, j));
  32. }
  33. }
  34.  
  35. sort(pos + 1, pos + 1 + L);
  36.  
  37. for (right = 1; right <= L; right++) {
  38. fr[pos[right].second.first]++;
  39. if (fr[pos[right].second.first] == 1)
  40. active++;
  41. while (fr[pos[left].second.first] > 1) {
  42. fr[pos[left].second.first]--;
  43. left++;
  44. }
  45.  
  46. if (active == N) {
  47. if (ans > pos[right].first - pos[left].first) {
  48. ans = pos[right].first - pos[left].first;
  49. best_left = left;
  50. best_right = right;
  51. }
  52. }
  53. }
  54.  
  55. for (int i = best_left; i <= best_right; i++) {
  56. out[pos[i].second.first] = pos[i].second.second;
  57. }
  58.  
  59. fprintf(file_out, "%lld\n", ans);
  60. for (int i = 1; i <= N; i++) {
  61. fprintf(file_out, "%d", out[i]);
  62. if (i < N) {
  63. fprintf(file_out, " ");
  64. }
  65. }
  66.  
  67. return 0;
  68. }
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement