Advertisement
Guest User

Untitled

a guest
Mar 13th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <time.h>
  5. #include <cstdio>
  6. #include <algorithm>
  7. #include <vector>
  8. #include <list>
  9.  
  10. using namespace std;
  11.  
  12. typedef long long lint;
  13.  
  14. const int N = 100 * 1000 + 7;
  15. const lint NN = 1000 * 1000*1000;
  16. int a[N];
  17. vector<int> aa;
  18. int b[N];
  19. vector<int> bb;
  20.  
  21. int maxa, maxb;
  22. int n, m;
  23.  
  24. int main() {
  25.     //freopen("input.txt", "r", stdin);
  26.     //freopen("output.txt", "w", stdout);
  27.     cin >> n >> m;
  28.     for (int i = 0; i < n; i++) {
  29.         cin >> a[i];
  30.         if (i == 0)
  31.             maxa = a[i];
  32.         else
  33.             if (a[i] > maxa)
  34.                 maxa = a[i];
  35.     }
  36.     for (int i = 0; i < n; i++) {
  37.         if (maxa == a[i])
  38.             aa.push_back(i);
  39.     }
  40.     for (int i = 0; i < m; i++) {
  41.         cin >> b[i];
  42.         if (i == 0)
  43.             maxb = b[i];
  44.         else
  45.             if (b[i] > maxb)
  46.                 maxb = b[i];
  47.     }
  48.     for (int i = 0; i < m; i++) {
  49.         if (maxb == b[i])
  50.             bb.push_back(i);
  51.     }
  52.     lint res = 0;
  53.     for (int i = 0, j = 0; i < n; i++) {
  54.         for (; i <= aa[0]; i++) {
  55.             res += a[i] * NN + b[0];
  56.         }
  57.         for (j = 0; j < bb[0]; j++) {
  58.             res += a[i] * NN + b[j];
  59.         }
  60.         if (aa.size() >= 2) {
  61.             // down
  62.             for( ; i<aa[1]; i++)
  63.                 res += a[i] * NN + b[j];
  64.            
  65.             for (; j < m; j++) {
  66.                 res += a[i] * NN + b[j];
  67.             }
  68.             for (; i < n; i++) {
  69.                 res += a[i] * NN + b[j];
  70.             }
  71.         }
  72.         else {
  73.             // right
  74.             for (; j < m; j++)
  75.                 res += a[i] * NN + b[j];
  76.             for (; i < n; i++) {
  77.                 res += a[i] * NN + b[j];
  78.             }
  79.         }
  80.     }
  81.     cout << res << endl;
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement