Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<algorithm>
- #include<stdio.h>
- #include<math.h>
- #include<set>
- #include<vector>
- #include<string.h>
- #include<string>
- using namespace std;
- int arrstart[14326];
- int arrend[14326];
- int a[14326];
- bool assert(bool t)
- {
- if (!t)
- throw 42;
- return true;
- }
- int cntOst(int a, int b)
- {
- int res = a%b;
- if (res < 0)
- res += b;
- return res;
- }
- int main()
- {
- #ifdef _DEBUG
- freopen("in.txt","r",stdin);
- #endif
- int m;
- cin >> m;
- int zeroCnt = 0;
- int ost = -1;
- int sum1=0,sum2=0;
- for (int i=0; i<m; i++)
- {
- cin >> arrstart[i];
- sum1 += arrstart[i];
- if (arrstart[i] == 0)
- zeroCnt++;
- }
- if (zeroCnt > 1)
- {
- cout << "-1";
- return 0;
- }
- for (int j=0; j<m; j++)
- {
- cin >> arrend[j];
- sum2 += arrend[j];
- }
- if (sum1 != sum2)
- {
- cout << "-1";
- return 0;
- }
- int maxdiff = 0;
- for (int i=0; i<m; i++)
- {
- int curr = cntOst(arrend[i]-arrstart[i],m);
- if (arrend[i]-arrstart[i] < maxdiff)
- maxdiff = arrend[i]-arrstart[i];
- if (ost == -1)
- ost = curr;
- else
- {
- if (ost != curr)
- {
- cout << "-1";
- return 0;
- }
- }
- }
- maxdiff *= -1;
- int N = m - ost;
- while(N == 0 || N < maxdiff)
- N += m;
- for (int i=0; i<m; i++)
- {
- a[i] = (arrend[i] - arrstart[i] + N) / m;
- }
- cout << N << endl;
- for (int i=0; i<N; i++)
- {
- bool minus = true;
- for (int j=0; j<m; j++)
- {
- if (arrstart[j] == 0)
- {
- arrstart[j] += (m-1);
- a[j]--;
- minus = false;
- cout << (j+1) << " ";
- }
- else
- {
- arrstart[j]--;
- }
- }
- if (minus)
- {
- int w=0;
- while (a[w] == 0 && assert(a[w] >= 0))
- w++;
- a[w]--;
- arrstart[w] += m;
- cout << w+1 << " ";
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment