【Codeforces 1108E1】Array and Segments (Easy version)
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
枚举最大值和最小值在什么地方。
显然,只要包含最小值的区间,都让他减少。
因为就算那个区间包含最大值,也无所谓,因为不会让答案变小。
但是那些不包含最大值的区间却能让差值变大。
所以没有问题。
【代码】
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 300;
int n,m;
int a[N+10],segl[N+10],segr[N+10];
int cnt[N+10],idxi;
int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> m;
for (int i = 1;i <= n;i++){
cin >> a[i];
}
for (int i = 1;i <= m;i++){
cin >> segl[i] >> segr[i];
}
int ans = 0,anscnt=0;
for (int i = 1;i <= n;i++)//a[i]最大
for (int j = 1;j <= n;j++){//a[j]最小
int x = a[i],y = a[j];
int cnt = 0;
for (int l = 1;l <= m;l++){
if (segl[l]<=j && j <= segr[l]){
cnt++;
y--;
if (segl[l]<=i && i <= segr[l]){
x--;
}
}
}
if (x-y>ans){
ans = x-y;
idxi = j;
anscnt = cnt;
}
}
cout<<ans<<endl;
cout<<anscnt<<endl;
for (int l = 1;l <= m;l++){
if (segl[l]<=idxi && idxi<=segr[l]){
cout<<l<<" ";
}
}
return 0;
}
【Codeforces 1108E1】Array and Segments (Easy version)的更多相关文章
- 【Codeforces 1118D1】Coffee and Coursework (Easy version)
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 从小到大枚举天数. 然后贪心地,从大到小分配a[i]到各个天当中. a[n]分配到第1天,a[n-1]分配到第2天,...然后a[n-x]又分 ...
- 【20.51%】【codeforces 610D】Vika and Segments
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 797E】Array Queries
[题目链接]:http://codeforces.com/problemset/problem/797/E [题意] 给你一个n个元素的数组; 每个元素都在1..n之间; 然后给你q个询问; 每个询问 ...
- Array and Segments (Easy version) CodeForces - 1108E1 (暴力枚举)
The only difference between easy and hard versions is a number of elements in the array. You are giv ...
- 【CodeForces 624D】Array GCD
题 You are given array ai of length n. You may consecutively apply two operations to this array: remo ...
- 【Codeforces 1185C2】Exam in BerSU (hard version)
[链接] 我是链接,点我呀:) [题意] 要让前i个数字的和小于等于M. 问你最少要删掉前i-1个数字中的多少个数字,每个询问都是独立的. [题解] ti的范围很小. 所以N*MAX(TI)暴力枚举就 ...
- E1. Array and Segments (Easy version)(暴力) && E2. Array and Segments (Hard version)(线段树维护)
题目链接: E1:http://codeforces.com/contest/1108/problem/E1 E2:http://codeforces.com/contest/1108/problem ...
- Codeforces 1108E2 Array and Segments (Hard version) 差分, 暴力
Codeforces 1108E2 E2. Array and Segments (Hard version) Description: The only difference between eas ...
- Codeforces Round #535 (Div. 3) E2. Array and Segments (Hard version) 【区间更新 线段树】
传送门:http://codeforces.com/contest/1108/problem/E2 E2. Array and Segments (Hard version) time limit p ...
随机推荐
- 优先队列 POJ 3253 Fence Repair
题目传送门 题意:一块木板按照某个顺序切成a[1], a[2]...a[n]的长度,每次切都会加上该两段木板的长度,问选择什么顺序切能使得累加和最小 分析:网上说这是哈夫曼树.很容易想到先切掉最长的, ...
- Eclipse Neon Java版本安装Java EE插件
Help→Install New Software 地址:Neon - http://download.eclipse.org/releases/neon/201703231000 选择 Web,X ...
- 你不知道的border-radius
对于border-radius这个属性,我们知道它可以用来设置边框圆角,利用它我们可以画出很多形状 这就需要了解到border-radius的各式写法: border-radius的写法: 1.只设置 ...
- mysql replication错误常见处理
大部分的错误,都是日志错误 日志本身的错误 主日志和中继日志都可能出错,可以使用mysqlbinlog来读一下mysqlbinlog mysql-bin.000007>/dev/null ##只 ...
- JAVA字符串转日期或日期转字符串【转】
JAVA字符串转日期或日期转字符串[转] 文章中,用的API是SimpleDateFormat,它是属于java.text.SimpleDateFormat,所以请记得import进 来! 用法: S ...
- SecureCRT中vi或vim编辑器显示中文乱码问题
vi ~/.vimrc //新建文件 syntax on set showmode set autowrite set number set encoding=utf-8 fileencodings ...
- const和volatile
const是只读变量 const修饰的变量是只读的,其本质还是变量 const修饰的局部变量在栈上分配空间 const修饰的全局变量在全局数据区分配空间 const只在编译期有用,在运行期无用 con ...
- CentOS下JRE环境变量配置
很多时候,我们需要在CentOS上部署tomcat,从而搭建web服务器,然JDK/JRE环境是前提,这里就记录一下,在后面的时候直接使用. 下载jre-7u80-linux-x64.tar.gz,并 ...
- MongoDB最简单的入门教程之一 环境搭建
MongoDB是近年来非常流行的一个介于关系数据库和非关系数据库之间的解决方案,特别广泛地应用于国内很多互联网公司,是非关系数据库当中功能最丰富,最像关系数据库的. MongoDB支持的数据结构非常松 ...
- vc++创建多线程应用
构建线程参数结构体: typedef struct { int nIndex; HANDLE hThread; int param1; ... }ThreadParam; 创建线程数组: Thread ...