結果
問題 |
No.871 かえるのうた
|
ユーザー |
![]() |
提出日時 | 2020-05-13 08:53:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 36 ms / 2,000 ms |
コード長 | 881 bytes |
コンパイル時間 | 1,635 ms |
コンパイル使用メモリ | 169,044 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-30 11:01:24 |
合計ジャッジ時間 | 3,645 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 49 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=(0);i<(n);i++) using namespace std; typedef long long ll; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; k--; vector<ll> x(n), a(n); rep(i, n) cin >> x[i]; rep(i, n) cin >> a[i]; int ans = 1; ll mx = x[k] + a[k]; ll mn = x[k] - a[k]; int l = k - 1; int r = k + 1; bool updated = true; while(updated){ updated = false; if(l >= 0 && x[l] >= mn){ updated = true; ans++; chmax(mx, x[l] + a[l]); chmin(mn, x[l] - a[l]); l--; } if(r < n && x[r] <= mx){ updated = true; ans++; chmax(mx, x[r] + a[r]); chmin(mn, x[r] - a[r]); r++; } } cout << ans << endl; }