| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 555333 | 600Mihnea | Sightseeing in Kyoto (JOI22_kyoto) | C++17 | 29 ms | 3152 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
bool home = 1;
using namespace std;
typedef long long ll;
const int N=(int)1e5+7;
const ll INF=(ll)1e18+7;
int n;
int m;
ll a[N];
ll b[N];
signed main() {
#ifdef ONLINE_JUDGE
  home = 0;
#endif
  home = 0;
  if (home) {
    freopen("I_am_iron_man", "r", stdin);
  }
  else {
    ios::sync_with_stdio(0); cin.tie(0);
  }
  vector<int> shib_a, shib_b;
  cin>>n>>m;
  for (int i=1;i<=n;i++) {
    cin>>a[i];
    while (1) {
      if((int)shib_a.size()<2) break;
      int p1=shib_a[(int)shib_a.size()-2];
      int p2=shib_a[(int)shib_a.size()-1];
      if((a[i]-a[p2])*(p2-p1)<(a[p2]-a[p1])*(i-p2)) {
        shib_a.pop_back();
      }else{
        break;
      }
    }
    shib_a.push_back(i);
  }
  for (int i=1;i<=m;i++) {
    cin>>b[i];
    while (1) {
      if((int)shib_b.size()<2) break;
      int p1=shib_b[(int)shib_b.size()-2];
      int p2=shib_b[(int)shib_b.size()-1];
      if((b[i]-b[p2])*(p2-p1)<(b[p2]-b[p1])*(i-p2)) {
        shib_b.pop_back();
      }else{
        break;
      }
    }
    shib_b.push_back(i);
  }
  n=(int)shib_a.size()-1;
  m=(int)shib_b.size()-1;
  ll sol=0;
  int i=0,j=0;
  while(i<n||j<m){
    bool dojo=0;
    if(i==n){
      dojo=1;
    }else{
      if(j==m){
        dojo=0;
      }else{
        assert(i<n&&j<m);
        ll a1=shib_a[i];
        ll a2=shib_a[i+1];
        ll b1=shib_b[j];
        ll b2=shib_b[j+1];
        if((a[a2]-a[a1])*(b2-b1)>(b[b2]-b[b1])*(a2-a1)){
          dojo=1;
        }else{
          dojo=0;
        }
      }
    }
    if(dojo==0){
      assert(i<n);
      sol+=(shib_a[i+1]-shib_a[i])*b[shib_b[j]];
      i++;
    }else{
      assert(j<m);
      sol+=(shib_b[j+1]-shib_b[j])*a[shib_a[i]];
      j++;
    }
  }
  cout<<sol<<"\n";
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
