fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4.  
  5. void sort(int a[][5],int x,int y)
  6. {
  7. int temp,i,j,p;
  8. i=x;
  9. for(p=0;p<y;p++)
  10. {
  11. for(j=p+1;j<y;j++)
  12. {
  13. if(a[i][p]>a[i][j])
  14. {
  15. temp=a[i][p];
  16. a[i][p]=a[i][j];
  17. a[i][j]=temp;
  18. }
  19. }}
  20. }
  21. int main()
  22. {
  23. int a[50][5];
  24. int n;
  25. int i,p,temp,sum,j,m,s;
  26. scanf("%d",&n);
  27. for(i=0;i<n;i++)
  28. {
  29. for(j=0;j<5;j++)
  30. {
  31. scanf("%d",&a[i][j]);
  32. }
  33. }
  34. for(i=0;i<n;i++)
  35. {
  36. sort(a,i,5);
  37. }
  38. for(m=0;m<n;m++)
  39. {
  40. for(s=0;s<5;s++)
  41. {
  42. //printf("%d\t",a[m][s]);
  43. }
  44. }
  45. i=n-1;
  46. for(j=4;j>=0;j--)
  47. {
  48. if(i==n-1)
  49. {
  50. temp=a[i][j];
  51. sum=temp;
  52. }
  53. if(temp>a[i-1][j])
  54. {
  55. sum=sum+a[i-1][j];
  56. temp=a[i-1][j];
  57. i--;
  58. }
  59. else{
  60. for(p=j;p>=0;p--)
  61. {
  62. if(temp>a[i-1][p-1]){
  63. sum=sum+a[i-1][p-1];
  64. temp=a[i-1][p-1];
  65. i--;
  66. break;
  67. }
  68. }
  69. }
  70. }
  71. printf("%d",sum);
  72. }
  73.  
  74.  
Success #stdin #stdout 0s 16064KB
stdin
5 
1089,3234 
6740,2803 
9243,2638 
4865,4355 
5993,8946
stdout
-1117973876