尺取法模板
注意 每次取出的钱不能超过ATM机剩余的余额:
s
u
m
+
a
[
t
]
+
S
>
=
0
sum + a[t] + S >= 0
sum+a[t]+S>=0
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28typedef long long ll; const int N = 2e5+10; int n; ll S, a[N]; void solve() { scanf("%d %lld", &n, &S); for(int i = 1; i <= n; i++) scanf("%lld", &a[i]); int res = 0; ll sum = 0; int s = 1, t = 1, l = 0, r = 0; while(1) { while(t <= n && sum + a[t] + S >= 0) sum += a[t++]; //if(sum + S < 0) break; // if(t - s > res) { res = t - s; l = s; r = t - 1; } if(t >= n && s >= n) break; sum -= a[s++]; } if(!res) printf("-1n"); else printf("%d %dn",l,r); }
最后
以上就是优秀大树最近收集整理的关于1614C Divan and bitwise operations的全部内容,更多相关1614C内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复