codeforces1373F. Network Coverage
程序员文章站
2022-06-21 19:22:52
可以二分b[1]给a[1]的值,看了standing学了种O(n)的办法,每次求a[i]-b[i-1],若大于0,则累加到下一次(a[i]只能有b[i]和b[i+1])组成,然后判断这个值和b[i]的大小#include using namespace std;typedef long long ll;int main() {ios::sync_with_stdio(0); cin.tie(0);int t;cin >> t;...
可以二分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;
}
}
本文地址:https://blog.csdn.net/qq_37765455/article/details/107125940
上一篇: .NET与你若只如初见(一)
推荐阅读
-
【解决】could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network
-
vue 集成 vis-network 实现网络拓扑图
-
putty network error:Connection refused 乱码解决方法
-
使用 linux 模拟广域网延迟 - Emulating wide area network delays with Linux
-
PHP_NETWORK_GETADDRESSES: GETADDRINFO FAILED问题解决办法
-
Windows Server 2003系统进程中NETWORK SERVICE相关知识详解
-
oracle impdp network_link参数使用介绍
-
IP default-network和静态路由区别
-
thunder network是什么文件夹?thunder network删除详细方法
-
Linux /etc/network/interfaces配置接口方法