Codeforces Round #485 (Div. 2) C题求三元组(思维)
1 second
256 megabytes
standard input
standard output
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are nn displays placed along a road, and the ii-th of them can display a text with font size sisi only. Maria Stepanovna wants to rent such three displays with indices i<j<ki<j<k that the font size increases if you move along the road in a particular direction. Namely, the condition si<sj<sksi<sj<sk should be held.
The rent cost is for the ii-th display is cici. Please determine the smallest cost Maria Stepanovna should pay.
The first line contains a single integer nn (3≤n≤30003≤n≤3000) — the number of displays.
The second line contains nn integers s1,s2,…,sns1,s2,…,sn (1≤si≤1091≤si≤109) — the font sizes on the displays in the order they stand along the road.
The third line contains nn integers c1,c2,…,cnc1,c2,…,cn (1≤ci≤1081≤ci≤108) — the rent costs for each display.
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices i<j<ki<j<k such that si<sj<sksi<sj<sk.
5
2 4 5 4 10
40 30 20 10 40
90
3
100 101 100
2 4 5
-1
10
1 2 3 4 5 6 7 8 9 10
10 13 11 14 15 12 13 13 18 13
33
In the first example you can, for example, choose displays 11, 44 and 55, because s1<s4<s5s1<s4<s5 (2<4<102<4<10), and the rent cost is 40+10+40=9040+10+40=90.
In the second example you can't select a valid triple of indices, so the answer is -1.
题意:选三个数,要求:i<j<k 且a[i]<a[j]<a[k],要求选出来的三个数的权值最小
思路:开始总想的是贪心,二分啥啥啥的。。。结果仔细想了下,他的范围是3000, O(n^3)的时间复杂度肯定不行,O(n^2)就可以过
只要我预处理第三个数,在每个数这从后面找一个权值最小且大于它的数,以此来作为第三个数即可,后面只要枚举两个数即可
#include<cstdio>
#include<cmath>
#include<iostream>
#define ll long long
using namespace std;
ll a[],b[],dp[];
int main() {
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d",&a[i]);
for(int i=;i<n;i++)
scanf("%d",&b[i]);
for(int i=;i<n;i++)
{
ll mn=;
for(int j=i+;j<n;j++) {
if(a[i]<a[j]) {
mn=min(mn,b[j]);
}
}
dp[i]=mn;
}
ll ans=;
for(int i=;i<n;i++)
{
for(int j=i+;j<n;j++)
{
if(a[i]<a[j])
{
if(dp[j]!=)
ans=min(ans,b[i]+b[j]+dp[j]);
}
}
}
if(ans==) printf("-1\n");
else cout<<ans<<endl;
}
总结:总的来说这次cf div2的题目不是很难,只是自己刷提还是刷的太少了,没想到思路就卡到了,训练太少,刷题太慢,需要好好反省
规律题总结,看到那种遍历一遍就超时那就肯定是规律题,一 班自己先把公式推出来,然后写个小枚举,把答案输出出来,然后自己再把递推公式推出来,再求解即可
Codeforces Round #485 (Div. 2) C题求三元组(思维)的更多相关文章
- Codeforces Round #485 (Div. 2)
Codeforces Round #485 (Div. 2) https://codeforces.com/contest/987 A #include<bits/stdc++.h> us ...
- Codeforces Round #485 (Div. 2) F. AND Graph
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- Codeforces Round #485 (Div. 2) D. Fair
Codeforces Round #485 (Div. 2) D. Fair 题目连接: http://codeforces.com/contest/987/problem/D Description ...
- Codeforces Round #485 (Div. 2) E. Petr and Permutations
Codeforces Round #485 (Div. 2) E. Petr and Permutations 题目连接: http://codeforces.com/contest/987/prob ...
- Codeforces Round #485 (Div. 2) C. Three displays
Codeforces Round #485 (Div. 2) C. Three displays 题目连接: http://codeforces.com/contest/987/problem/C D ...
- Codeforces Round #485 (Div. 2) A. Infinity Gauntlet
Codeforces Round #485 (Div. 2) A. Infinity Gauntlet 题目连接: http://codeforces.com/contest/987/problem/ ...
- Codeforces Round #713 (Div. 3)AB题
Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...
随机推荐
- Exception:public class feign.codec.EncodeException feign.codec.EncodeException: 'Content-Type' cannot contain wildcard type '*'
一.异常出现的场景 Spring Cloud 服务A通过feign调用服务B;之前是好好的,但今天突然就不好了,抛以下异常===> 出现原因补充,Spring Boot默认的JSON方式 Ja ...
- Java -------- 首字母相关排序总结
Java 字符串数组首字母排序 字符串数组按首字母排序:(区分大小写) String[] strings = new String[]{"ba","aa",&q ...
- drf 生成接口文档
REST framework可以自动帮助我们生成接口文档.接口文档以网页的方式呈现. 自动接口文档能生成的是继承自APIView及其子类的视图. 一.安装依赖 REST framewrok生成接口文档 ...
- php字符串的拆分截取
/* * strstr区分大小写 * stristr不区分大小写 * */ $str="test/abc.jpg"; echo stristr($str,'.'); echo '& ...
- Bacterial Melee CodeForces - 756D (dp去重)
大意: 给定字符串, 每次可以任选一个字符$x$, 将$x$左侧或右侧也改为$x$, 求最终能得到多少种字符串. 首先可以观察到最终字符串将连续相同字符合并后一定是原字符串的子序列 并且可以观察到相同 ...
- leetcode-algorithms-6 ZigZag Conversion
leetcode-algorithms-6 ZigZag Conversion The string "PAYPALISHIRING" is written in a zigzag ...
- 26. Remove Duplicates from Sorted Array C++ 删除排序数组中的重复项
https://leetcode.com/problems/remove-duplicates-from-sorted-array/ 双指针,注意初始时左右指针指向首元素! class Solutio ...
- Python----list&元祖常用方法总结
一.创建列表,把使用逗号分隔的数据用中括号[ ]括起来即为一个列表,列表也叫数组.list.array:列表里面也可以再套列表,一个列表里面套一个列表,叫二维数组:一个里面套一个列表,里面的列表再套 ...
- ISO/OSI七层网络参考模型、TCP/IP四层网络模型和教学五层网络模型
一.说明 直接的原因是昨晚<计算机网络(自顶向下方法)>到货了,以为能讲得有些不一样,但看完整本也就是老调地讲过来讲应用层.传输层.网络层.网络接口层.感觉比之谢希仁的<计算机网络& ...
- adb(Android Debug Bridge)安装使用教程
一.说明 adb的db是debug bridge而不是和gdb一样指debug,这意思是说adb不能像gdb那样能一步步调试代码,但可以启到一些类似调试的功能. 下面就针对这些功能进行介绍,本文根据官 ...