結果
問題 | No.1965 Heavier |
ユーザー |
|
提出日時 | 2022-06-03 22:23:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 355 ms / 2,000 ms |
コード長 | 1,105 bytes |
コンパイル時間 | 1,636 ms |
コンパイル使用メモリ | 172,296 KB |
実行使用メモリ | 25,216 KB |
最終ジャッジ日時 | 2024-09-21 02:54:33 |
合計ジャッジ時間 | 6,980 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;using pll = pair<ll, ll>;#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)#define rep(i, n) drep(i, 0, n - 1)#define all(a) (a).begin(), (a).end()#define pb push_back#define fi first#define se secondconst ll MOD = 1000000007;const ll MOD2 = 998244353;const ll INF = 1LL << 60;const ll N_MAX = 2e5;int main(){ll n;cin >> n;vector<ll> a(n), b(n);rep(i, n) cin >> a[i];rep(i, n) cin >> b[i];ll ans = 0;multiset<ll> p, m;for(ll l=0, r=0; l<n-1; l++){if(l == r){p.insert(a[l]+b[l]);m.insert(a[l]-b[l]);r++;}if(r < n){while(p.lower_bound(a[r]+b[r])==p.end() && m.lower_bound(a[r]-b[r])==m.end()){p.insert(a[r]+b[r]);m.insert(a[r]-b[r]);r++;if(r == n) break;}}ans += (r-l-1);p.erase(p.lower_bound(a[l]+b[l]));m.erase(m.lower_bound(a[l]-b[l]));}cout << ans << endl;}