当前位置: 代码迷 >> 综合 >> codeforces1373F. Network Coverage
  详细解决方案

codeforces1373F. Network Coverage

热度:10   发布时间:2023-11-24 00:29:21.0

可以二分b[1]给a[1]的值,看了standing学了种O(n)的办法,每次求a[i]-b[i-1],若大于0,则累加到下一次(a[i]只能有b[i]和b[i+1])组成,然后判断这个值和b[i]的大小

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;int main() {ios::sync_with_stdio(0); cin.tie(0);int t;cin >> t;while (t--) {int n;cin >> n;vector<ll> a(n), b(n);ll balance = 0;for (ll& v : a) cin >> v, balance += v;for (ll& v : b) cin >> v, balance -= v;ll worst = 0, ok = 1;for (int i = 1; i <2 * n; i++) {worst = max(0ll, worst) + a[i % n] - b[(i - 1) % n];if (worst > b[i % n]) ok = 0;}cout << (balance > 0 || ok == 0 ? "NO" : "YES") << endl;}
}

 

  相关解决方案