fork(7) download
  1. #include <ext/pb_ds/assoc_container.hpp>
  2. #include <ext/pb_ds/tree_policy.hpp>
  3. #include <bits/stdc++.h>
  4.  
  5. using namespace __gnu_pbds;
  6. using namespace std;
  7.  
  8. typedef
  9. tree<
  10. pair<int,int>,
  11. null_type,
  12. greater<pair<int,int>>,
  13. rb_tree_tag,
  14. tree_order_statistics_node_update>
  15. order_set;
  16.  
  17. main()
  18. {
  19. ios::sync_with_stdio(0);
  20. cin.tie(0);
  21. int n,k,sz=0;
  22. cin>>n>>k;
  23. int ans=0,ansi=0;
  24. for(int i=0;i<k;i++)
  25. {
  26. order_set t;
  27. int cur=0,x;
  28. for(int j=0;j<n;j++)
  29. {
  30. cin>>x;
  31. cur+=t.order_of_key({x,++sz});
  32. t.insert({x,sz});
  33. }
  34. if(cur>ans)
  35. ansi=i,ans=cur;
  36. }
  37. cout<<ansi+1<<endl;
  38. }
Success #stdin #stdout 0s 3440KB
stdin
3 3
1 2 3
2 1 3
3 2 1
stdout
3