Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. ///2017 I problema 2
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. void alg(int a[],int b[],int n,int m,bool &raspuns,
  7. int &k,int &nrMax)
  8. {
  9. int i,c=1,s=0,secv=0;
  10. nrMax = -1;
  11. for(i=1;i<=n;++i)
  12. {
  13. if(c>m)
  14. break;
  15. s+=a[i];
  16. secv++;
  17. if(s==b[c])
  18. {
  19. if(secv>nrMax)
  20. {
  21. k = c;
  22. nrMax=secv;
  23. }
  24. s=secv=0;c++;
  25. }
  26. else if(s>b[c])
  27. {
  28. raspuns = false;
  29. k=nrMax=-1;
  30. return;
  31. }
  32. }
  33. if(i==n+1 && c==m+1)
  34. raspuns = true;
  35. else
  36. {
  37. raspuns = false;
  38. k=nrMax=-1;
  39. }
  40. }
  41. int main()
  42. {
  43. int n,m,a[101],b[101],x,k;
  44. bool r;
  45. cin>>n;
  46. for(int i=1;i<=n;++i)
  47. cin>>a[i];
  48. cin>>m;
  49. for(int i=1;i<=m;++i)
  50. cin>>b[i];
  51. alg(a,b,n,m,r,k,x);
  52. cout<<r<<' '<<x;
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement