Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <time.h>
- #include <cstdio>
- #include <algorithm>
- #include <vector>
- #include <list>
- using namespace std;
- typedef long long lint;
- const int N = 100 * 1000 + 7;
- const lint NN = 1000 * 1000*1000;
- int a[N];
- vector<int> aa;
- int b[N];
- vector<int> bb;
- int maxa, maxb;
- int n, m;
- int main() {
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- cin >> n >> m;
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- if (i == 0)
- maxa = a[i];
- else
- if (a[i] > maxa)
- maxa = a[i];
- }
- for (int i = 0; i < n; i++) {
- if (maxa == a[i])
- aa.push_back(i);
- }
- for (int i = 0; i < m; i++) {
- cin >> b[i];
- if (i == 0)
- maxb = b[i];
- else
- if (b[i] > maxb)
- maxb = b[i];
- }
- for (int i = 0; i < m; i++) {
- if (maxb == b[i])
- bb.push_back(i);
- }
- lint res = 0;
- for (int i = 0, j = 0; i < n; i++) {
- for (; i <= aa[0]; i++) {
- res += a[i] * NN + b[0];
- }
- for (j = 0; j < bb[0]; j++) {
- res += a[i] * NN + b[j];
- }
- if (aa.size() >= 2) {
- // down
- for( ; i<aa[1]; i++)
- res += a[i] * NN + b[j];
- for (; j < m; j++) {
- res += a[i] * NN + b[j];
- }
- for (; i < n; i++) {
- res += a[i] * NN + b[j];
- }
- }
- else {
- // right
- for (; j < m; j++)
- res += a[i] * NN + b[j];
- for (; i < n; i++) {
- res += a[i] * NN + b[j];
- }
- }
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement