Advertisement
a53

sss

a53
Dec 6th, 2021
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include<iostream>
  2. #define MAXN 1000000
  3. #define MAXM 1000000
  4. using namespace std;
  5. int a[MAXN],b[MAXM];
  6. void output_ans (pair <int, int> l, pair <int, int> r) {
  7. cout << r.first-l.first << "\n";
  8. for (int i=l.first+1; i<=r.first; i++) {
  9. cout << i << " ";
  10. }
  11. cout << "\n" << r.second-l.second << "\n";
  12. for (int i=l.second+1; i<=r.second; i++) {
  13. cout << i << " " ;
  14. }
  15. }
  16. pair <int, int> diff[MAXN+MAXM];
  17. int main () {
  18. ios_base::sync_with_stdio(false);
  19. cin.tie(NULL);
  20. cout.tie(NULL);
  21.  
  22. int n,m;
  23. cin >> n ;
  24. for (int i=0; i<n; i++) {
  25. cin >> a[i] ;
  26. }
  27. cin >> m ;
  28. for (int i=0; i<m; i++) {
  29. cin >> b[i] ;
  30. }
  31. long long int sumA=0,sumB=0;
  32. int indA=0,indB=0;
  33. for (;;) {
  34. if ((indA==n)&&(indB==m)) break;
  35. if (sumA<sumB) {
  36. if (indA==n) break;
  37. sumA+=a[indA++];
  38. }
  39. else {
  40. if (indB==m) break;
  41. sumB+=b[indB++];
  42. }
  43. if (sumA==sumB) {
  44. output_ans({-1,-1},{indA-1,indB-1});
  45. break;
  46. }
  47. if (diff[sumA-sumB+n]!=make_pair(0,0)) {
  48. output_ans(diff[sumA-sumB+n],{indA-1,indB-1});
  49. break;
  50. }
  51. diff[sumA-sumB+n]={indA-1,indB-1};
  52. }
  53. cout << endl ;
  54. return 0;
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement