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