fork(1) download
  1. #include <stdio.h>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n;
  8. scanf("%d",&n);
  9.  
  10. vector <vector <int> > val;
  11.  
  12.  
  13. int size=0;
  14. for(int i=0;i<n;i++)
  15. {
  16.  
  17. scanf("%d",&size);
  18. int temp;
  19. vector <int> cur;
  20. for(int j=0;j<size;j++)
  21. {
  22. scanf("%d",&temp);
  23. cur.push_back(temp);
  24. }
  25. val.push_back(cur);
  26. }
  27.  
  28.  
  29. int ind[n];
  30. for(int i=0;i<n;i++)ind[i]=0;
  31.  
  32. int ans=0;
  33. int prev=-1;
  34. while(!done)
  35. {
  36. int done = true;
  37. int min =-1;
  38. int cur=-1;
  39. for(int i=0;i<n;i++)
  40. {
  41. if(ind[i]<val[i].size())
  42. {
  43. done = false;
  44. if(min==-1)
  45. {
  46. min = val[i][ind[i]];
  47. cur =i;
  48. // ind[i]++;
  49. }
  50. else
  51. {
  52. if(val[i][ind[i]]<min){min = val[i][ind[i]];cur=i;}
  53.  
  54. }
  55.  
  56. }
  57. }
  58.  
  59. if(!done)
  60. {
  61. // prev = cur;
  62. if(ind[cur]==val[cur].size()-1)
  63. {
  64. if(prev!=cur)ans++;
  65. }
  66. else
  67. {
  68. if(prev!=cur)ans+=2;
  69. }
  70. }
  71. }
  72.  
  73. printf("sum - %d\n",ans);
  74.  
  75. // for(int i=0;i<n;i++)
  76. // {
  77. // for(int j=0;j<val[i].size();j++)
  78. // {
  79. // printf("%d ",val[i][j]);
  80. // }
  81. // printf("\n");
  82. // }
  83.  
  84. return 0;
  85. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
2
3 1 2 4
2 3 5
compilation info
prog.cpp: In function 'int main()':
prog.cpp:34: error: 'done' was not declared in this scope
stdout
Standard output is empty