fork(4) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. //#include <ext/pb_ds/assoc_container.hpp> // Include for built in treap
  4. //#include <ext/pb_ds/tree_policy.hpp>
  5. //using namespace __gnu_pbds;
  6. const int MOD = 1e9 + 7;
  7. #define ll long long int
  8. #define pii pair<int, int>
  9. #define pll pair<ll, ll>
  10. #define pb push_back
  11. #define eb emplace_back
  12. #define in insert
  13. #define ff first
  14. #define ss second
  15. #define vi vector<int>
  16. #define vl vector<ll>
  17. #define vpii vector<pii>
  18. #define vpll vector<pll>
  19. #define si set<int>
  20. #define mpii map<int, int>
  21. #define prq priority_queue
  22. #define sz(s) (int) s.size()
  23. #define pf(a) printf("%d ",a)
  24. #define si1(a) scanf("%d",&a)
  25. #define si2(a,b) scanf("%d%d",&a,&b)
  26. #define si3(a,b,c) scanf("%d%d%d",&a,&b,&c)
  27. //#define scan(v) for(int i = 0; i<n; i++){int x;cin>>x;v.pb(x);}
  28. #define pi 2 * acos (0.0)
  29. #define inf 1e9
  30. #define co cout
  31. #define en '\n'
  32. #define re return
  33. #define con continue
  34. #define dbg cout<<"___________ok____________"<<endl;
  35. #define yes() printf("YES\n");
  36. #define no() puts("NO");
  37. #define FOR(i, j, k) for(int i=(j); i<(k); i++)
  38. #define REV(i, j, k) for(int i=(n-1); i>=k; i--)
  39. #define all(v) v.begin(), v.end()
  40. #define rnd(a, b) ((((rand()<<15)^rand())%((b)-(a) + 1))+(a))
  41. #define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL)
  42. #define mem(x, y) memset(x, y, sizeof(x))
  43. #define prn(v) for(auto x: v)cout<<x<<" ";
  44. //typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_ds;
  45. const double EPS = 1e-9;
  46. const int MXX = 2e5 + 5;
  47.  
  48. ll a[2005], b[2005], c[2005];
  49. int main()
  50. {
  51.  
  52. FAST_IO;
  53. ll n, m;cin>>n>>m;
  54. ll mxp = -1;
  55. for(ll i = 0; i<n; i++)cin>>a[i];
  56. for(ll i = 0; i<n; i++)cin>>b[i], mxp=max(mxp, b[i]),c[i] = b[i];
  57. sort(c, c + n);
  58. for(ll i = 0; i<=1e5; i++)
  59. {
  60. vector<ll>v;
  61. for(ll j = 0; j<n; j++)
  62. {
  63. v.pb((a[j] + i)%m);
  64. }
  65. sort(all(v));
  66. // if(i == 1) prn(v);re 0;
  67. bool f = 1;
  68. for(ll j = 0; j<n; j++)
  69. {
  70. if(c[j]!=v[j])
  71. {
  72. f = 0;break;
  73. }
  74. }
  75. if(f)return cout<<i<<endl, 0;
  76. }
  77. return 0;
  78. }
Time limit exceeded #stdin #stdout 5s 4280KB
stdin
Standard input is empty
stdout
Standard output is empty