fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. struct drawfix
  4. {
  5. int play,pos;
  6. };
  7. bool cmp(drawfix a,drawfix b)
  8. {
  9. return a.play>b.play;
  10. }
  11. int main()
  12. {
  13. ios_base::sync_with_stdio(0);
  14. vector<pair<int,int> > vec;
  15. int n,val,p,huge=numeric_limits<int>::max(),diff,c=0;
  16. cin>>n;
  17. drawfix siru[n+1];
  18. bool played[n+1];
  19. int nava[n+1];
  20. for(int i=1;i<=n;i++)
  21. {
  22. played[i]=false;
  23. cin>>siru[i].play;
  24. siru[i].pos=i;
  25. }
  26. for(int i=1;i<=n;i++)
  27. cin>>nava[i];
  28. sort(siru+1,siru+n+1,cmp);
  29. for(int x=1;x<=n;x++)
  30. {
  31. diff=huge;
  32. val=siru[x].play;
  33. for(int i=1;i<=n;i++)
  34. {
  35. if(!played[i])
  36. {
  37. if(val>nava[i] && val-nava[i]<diff)
  38. {
  39. diff=val-nava[i];
  40. p=i;
  41. }
  42. }
  43. }
  44. if(diff==huge)
  45. {
  46. for(int i=1;i<=n;i++)
  47. {
  48. if(!played[i])
  49. {
  50. p=i;
  51. break;
  52. }
  53. }
  54. }
  55. else
  56. c++;
  57. played[p]=true;
  58. vec.push_back(make_pair(siru[x].pos,p));
  59. }
  60. sort(vec.begin(),vec.end());
  61. cout<<c<<endl;
  62. for(int i=0;i<n;i++)
  63. cout<<vec[i].second<<endl;
  64. }
Success #stdin #stdout 0s 2868KB
stdin
4
1873
2134
1900
1600
2450
1860
1700
2120
stdout
3
3
4
2
1