fork download
  1. import java.io.*;
  2. public class Main {
  3. public static void main (String[]args)throws Exception{
  4.  
  5.  
  6. String[] first_line = read.readLine().split(" ");
  7. String[] []A = new String [50][];
  8. String empty;
  9. int []positions = new int [150];
  10. int []pancakes = new int [1000];
  11. String[] ing_bought;
  12. int []B = new int [150];
  13. double lowest;
  14. int i=0,c;
  15. int greatest,lowest2;
  16. int greatest_position;
  17. int u =0;
  18. while(Integer.parseInt(first_line[0])!=0 && Integer.parseInt(first_line[1])!=0){
  19. empty = read.readLine();
  20. if ("0".equals(first_line[0])){
  21. break;
  22. }
  23. ing_bought = read.readLine().split(" ");
  24.  
  25. for(i=0;i<Integer.parseInt(first_line[1]);i++){
  26. empty = read.readLine();
  27. A[i] = read.readLine().split(" ");
  28. }
  29.  
  30. for(i=0,c=0;i<Integer.parseInt(first_line[1]);i++,c=0){
  31. if ("0".equals(A[i][c])){
  32. A[i][c] = "1";
  33. }
  34.  
  35. lowest2 = Integer.parseInt(ing_bought[c])*10/Integer.parseInt(A[i][c]);
  36. for(c=1;c<Integer.parseInt(first_line[0]);c++){
  37. if ("0".equals(A[i][c])){
  38. A[i][c] = "1";
  39. }
  40.  
  41. if (Integer.parseInt(ing_bought[c])*10/Integer.parseInt(A[i][c]) < lowest2){
  42. lowest2 = Integer.parseInt(ing_bought[c])*10/Integer.parseInt(A[i][c]);
  43. }
  44. }
  45. B[i]=lowest2;
  46. }
  47.  
  48. greatest = (int)B[0];
  49. greatest_position=1;
  50. for(i=0;i<Integer.parseInt(first_line[1]);i++){
  51. if (B[i] > greatest){
  52. greatest = (int)B[i];
  53. greatest_position = i+1;
  54. }
  55. }
  56. if (greatest < 1){
  57. positions[u]=1;
  58. }
  59. positions[u]=greatest_position;
  60. pancakes[u]=greatest;
  61. // System.out.println(greatest_position + " " + greatest + "\n");
  62. empty = read.readLine();
  63. empty = read.readLine();
  64. empty = read.readLine();
  65.  
  66. first_line = read.readLine().split(" ");
  67. u++;
  68. }
  69. for(int l=0;l<u;l++){
  70. System.out.println(positions[l] + " " + pancakes[l] + "\n");
  71. }
  72. }
  73. }
  74.  
Success #stdin #stdout 0.09s 212416KB
stdin
3 2

20 20 20

5 10 1

2 1 3

 

6 3

100 60 130 80 100 90

10 5 10 5 10 5

1 2 1 2 20 7

0 0 0 10 30 1

 

0 0

 
stdout
2 66

1 100