Submission

Status:
(P--P-)(PPPP-P--PPPPPP-)

Score: 0

User: Ecir

Problemset: Nostalgia v2

Language: cpp

Time: 0.026 second

Submitted On: 2025-04-05 10:07:18

#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
#define twod array<ll,2>
ll arr[100009];
ll val[100009];
ll dp[200009];
priority_queue<twod,vector<twod>,greater<twod>> q;
int main(){
  ios::sync_with_stdio(0);cin.tie(0);
  int n;cin >> n;
  for(int i=1;i<=n;i++) cin >> arr[i];
  for(int i=1;i<=n;i++) cin >> val[i];
  for(int i=1;i<=n;i++) dp[i]=val[i]-arr[i];
  for(int i=1;i<=n;i++) dp[i+n]=val[i]-arr[i];
  for(int i=1;i<=2*n;i++) dp[i]+=dp[i-1];
  for(int i=1;i<=n;i++) q.push({dp[i],i});
  int ans=0;
  if(q.top()[0]>=0) ans++;
  for(int i=n+1;i<=2*n;i++){
    auto x=q.top();
    while(x[1]<=i-n){
      q.pop();
      x=q.top();
    }
    q.push({dp[i],i});
    x=q.top();
    if(x[0]>=dp[i-n]) ans++;
  }
  cout << ans;
  
  return 0;
}