fork(2) download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <climits>
  4.  
  5. using namespace std;
  6.  
  7. double INF = 1e18;
  8.  
  9. int sgn(long long a){
  10. if(a < 0) return -1;
  11. else if(a == 0) return 0;
  12. else return 1;
  13. }
  14.  
  15. struct logNumber{
  16. long long sign;
  17. double value;
  18. logNumber(int sign = 1, double value = 0){
  19. this->sign = sign;
  20. this->value = value;
  21. }
  22. void operator *= (long long a){
  23. sign *= sgn(a);
  24. if(sign == 0) value = 0;
  25. else value += log(abs(a));
  26. }
  27. bool operator >(logNumber a){
  28. return (sign > a.sign) or (sign == 1 and a.sign == 1 and value > a.value) or (sign == -1 and a.sign == -1 and value < a.value);
  29. }
  30. bool operator ==(logNumber a){
  31. return sign == a.sign and value == a.value;
  32. }
  33. };
  34.  
  35. int main() {
  36. cin.tie(NULL);
  37. ios_base::sync_with_stdio(false);
  38. int n,k;
  39. cin>>n>>k;
  40. logNumber mult[n];
  41. for(int i =0; i < k; i++){
  42. for(int j=0; j < n; j++){
  43. long long temp;
  44. cin>>temp;
  45. mult[j] *= temp;
  46. }
  47. }
  48. logNumber maxMult = mult[0];
  49. int maxTeam = 0;
  50. for(int i = 0; i < n; i++){
  51. if (mult[i] > maxMult){
  52. maxMult = mult[i];
  53. maxTeam = i;
  54. }
  55. else if(mult[i]==maxMult){
  56. maxTeam = max(i, maxTeam);
  57. }
  58. }
  59. cout << maxTeam + 1;
  60.  
  61.  
  62.  
  63.  
  64. return 0;
  65. }
Runtime error #stdin #stdout 0s 4352KB
stdin
Standard input is empty
stdout
Standard output is empty