Advertisement
Guest User

Untitled

a guest
Oct 14th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include<fstream>
  2. using namespace std;
  3. int const MAXN=100000;
  4.  
  5. int main()
  6.  
  7. {
  8. ifstream cin("input.txt");
  9. ofstream cout("output.txt");
  10. int n, A[MAXN], B[MAXN], diff[MAXN];
  11.  
  12. cin>>n;
  13.  
  14. for(int i=0;i<n;i++) cin>>A[i];
  15.  
  16. for(int i=0;i<n;i++) cin>>B[i];
  17.  
  18. for(int i=0;i<n;i++) diff[i]=B[i]-A[i];
  19.  
  20. int somma=0, lung=0, lungmax=0;
  21.  
  22. for(int i=0;i<n;i++)
  23.  
  24. {
  25.  
  26. lung=0;
  27.  
  28. somma=0;
  29.  
  30. for(int j=i;j<n;j++)
  31.  
  32. {
  33.  
  34. somma+=diff[j];
  35.  
  36. if(somma>=0) lung=j-i+1;
  37.  
  38. }
  39.  
  40.  
  41. lungmax=max(lungmax, lung);
  42.  
  43. }
  44.  
  45. cout<<lungmax;
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement