Educational Codeforces Round 88 (Rated for Div. 2) D、Yet Another Yet Another Task
for Codeforces div round Task another 88 yet
2023-09-27 14:26:03 时间
题意:
给你一个含n个数a1,a2...an的数组,你要找到一个区间[l,r],使得al+a(l+1)+...+a(r-1)+ar减去max(al,a(l+1),...,a(r-1),ar)的值尽可能大
n<=1e5
-30<=ai<=30
题解:
因为ai的范围特别小,我们可以枚举区间[l,r]的最大值,然后就是暴力循环(这一点看代码)
代码:
#include<stdio.h> #include<algorithm> #include<iostream> #include<string> #include<queue> #include<deque> #include<string.h> #include<map> #include <iostream> #include <math.h> #define Mem(a,b) memset(a,b,sizeof(a)) const double II = acos(-1); const double PP = (II*1.0)/(180.00); using namespace std; typedef long long ll; const int INF=0x3f3f3f3f; const int maxn=2e5+10; const double eps=1e-6; const double PI=acos(-1); int v[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> v[i]; } int sum = 0; int ans = 0; for (int i = 0; i <= 30; i++) //ö�����������ֵ { sum = 0; for (int j = 1; j <= n; j++) { if( v[j] > i ) sum = 0; else { sum += v[j]; if( sum < 0 ) sum = 0; ans = max(ans,sum-i); //�������� } } } cout << ans << '\n'; return 0; }
相关文章
- Installation request for topthink/think-captcha ^3.0 -> satisfiable by topthink/think-captcha[v3.0.0].
- GaussDB(for Influx)与开源企业版性能对比
- Gradle for Android 第五篇( 多模块构建 )
- goldengate Not able to establish initial position for begin time
- NTFS For (mac读写NTFS磁盘工具)V14.2.359简体中文版
- git Permanently added the RSA host key for IP address '13.250.177.223' to the list of known hosts.
- JS循环for、for...of、for...in
- 小程序:最难点For的wx:key
- Ubuntu 分辨率更改 xrandr Failed to get size of gamma for output default
- Exception in thread "AWT-EventQueue-0" javax.persistence.PersistenceException: No Persistence provider for EntityManager named null
- mysql(for update)悲观锁总结与实践
- Educational Codeforces Round 88 (Rated for Div. 2) E、Modular Stability 逆元+思维
- Educational Codeforces Round 88 (Rated for Div. 2) B、New Theatre Square C、Mixing Water
- 第88讲:Scala中使用For表达式实现map、flatMap、filter
- TMS VCL UI Pack v10.1.0.0 for 10.3-SEO狼术