a53

camioane1

a53
Feb 23rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include <fstream>
  2. #include <cstring>
  3. #include <iostream>
  4. #include <algorithm>
  5. #define Nmax 100002
  6. #define ll long long
  7. using namespace std;
  8.  
  9. ifstream f("camioane.in");
  10. ofstream g("camioane.out");
  11.  
  12. int n, m;
  13. int ans[Nmax];
  14. pair<pair<ll,ll>, int> A[Nmax], B[Nmax];
  15.  
  16. pair<ll,ll> StringToPair(string aux){
  17. pair<ll,ll> ans = {0,0};
  18. reverse(aux.begin(),aux.end());
  19. while (aux.size() > 16){
  20. ans.first = ans.first * 10 + aux.back() - '0';
  21. aux.pop_back();
  22. }
  23. while (!aux.empty()){
  24. ans.second = ans.second * 10 + aux.back() - '0';
  25. aux.pop_back();
  26. }
  27. return ans;
  28. }
  29.  
  30. int main()
  31. {
  32. f >> n >> m;
  33. string aux;
  34. for (int i=1;i<=n;i++){
  35. f >> aux;
  36. A[i].first = StringToPair(aux);
  37. A[i].second = i;
  38. }
  39. for (int i=1;i<=m;i++){
  40. f >> aux;
  41. B[i].first = StringToPair(aux);
  42. B[i].second = i;
  43. }
  44.  
  45. sort(A+1,A+n+1);
  46. sort(B+1,B+m+1);
  47.  
  48. int nr = 1;
  49. for (int i=1;i <= n && nr <= m;i++)
  50. if (A[i].first >= B[nr].first){ /// cautam traseul cu indicele A[i] cel mai mic pe care poate circula camionul C[nr]
  51. ans[A[i].second] = B[nr].second;
  52. nr++;
  53. }
  54.  
  55. g << nr-1 << '\n';
  56. for (int i=1;i<=n;i++){
  57. g << ans[i] << ' ';
  58. }
  59.  
  60. return 0;
  61. }
Add Comment
Please, Sign In to add comment