Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #define MAXN 1000000
- #define MAXM 1000000
- using namespace std;
- int a[MAXN],b[MAXM];
- void output_ans (pair <int, int> l, pair <int, int> r) {
- cout << r.first-l.first << "\n";
- for (int i=l.first+1; i<=r.first; i++) {
- cout << i << " ";
- }
- cout << "\n" << r.second-l.second << "\n";
- for (int i=l.second+1; i<=r.second; i++) {
- cout << i << " " ;
- }
- }
- pair <int, int> diff[MAXN+MAXM];
- int main () {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- int n,m;
- cin >> n ;
- for (int i=0; i<n; i++) {
- cin >> a[i] ;
- }
- cin >> m ;
- for (int i=0; i<m; i++) {
- cin >> b[i] ;
- }
- long long int sumA=0,sumB=0;
- int indA=0,indB=0;
- for (;;) {
- if ((indA==n)&&(indB==m)) break;
- if (sumA<sumB) {
- if (indA==n) break;
- sumA+=a[indA++];
- }
- else {
- if (indB==m) break;
- sumB+=b[indB++];
- }
- if (sumA==sumB) {
- output_ans({-1,-1},{indA-1,indB-1});
- break;
- }
- if (diff[sumA-sumB+n]!=make_pair(0,0)) {
- output_ans(diff[sumA-sumB+n],{indA-1,indB-1});
- break;
- }
- diff[sumA-sumB+n]={indA-1,indB-1};
- }
- cout << endl ;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement