Codeforces 1148 E - Earth Wind and Fire
思路:
栈模拟
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb emplace_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<int, pii>
#define puu pair<ULL, ULL>
#define pdd pair<long double, long double>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head int main() {
int n;
scanf("%d", &n);
vector<pii> a(n);
vector<int> b(n);
for (int i = ; i < n; ++i) scanf("%d", &a[i].fi), a[i].se = i;
for (int i = ; i < n; ++i) scanf("%d", &b[i]);
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<tuple<int, int,int>> res;
vector<pii> st;
for (int i = ; i < n; ++i) {
int d = b[i]-a[i].fi;
if(d == ) continue;
if(d > ) {
st.pb(d, a[i].se);
}
else {
while(d < ) {
if(st.empty()) return *puts("NO");
int dd = min(st.back().fi, -d);
d += dd;
st.back().fi -= dd;
res.pb(st.back().se, a[i].se, dd);
if(st.back().fi == ) st.pop_back();
}
}
}
if(!st.empty()) return *puts("NO");
printf("YES\n%d\n", (int)res.size());
for (auto p : res) printf("%d %d %d\n", get<>(p)+, get<>(p)+, get<>(p));
return ;
}
Codeforces 1148 E - Earth Wind and Fire的更多相关文章
- codeforces#1148E. Earth Wind and Fire(贪心)
题目链接: http://codeforces.com/contest/1148/problem/E 题意: 给出两个长度为$n$的序列,将第一个序列变成第二个序列,顺序不重要,只需要元素完全相同即可 ...
- Earth Wind and Fire CodeForces - 1148E (构造)
大意: $n$个石子, 第$i$个石子初始位置$s_i$, 每次操作选两个石子$i,j$, 要求$s_i<s_j$, 任取$d$, 满足$0\le 2d\le s_j-s_i$, 将$s_i,s ...
- Codeforces 1148E Earth Wind and Fire
分析 必要条件: ① $\sum_{i=1}^{n} s_i = \sum_{i=1}^{n} t_i$ 预处理: 将 $s, t$ 从小到大排序. 尝试一 首尾匹配.例子 s = 2, 2, 4, ...
- Earth Wind 一个查看全球风向的网站
可以查看整个地球的全貌 ,还能定位你的位置,特别是动画挺有意思 网址:https://earth.nullschool.net/#current/wind/surface/level/orthogra ...
- Codeforces Round #436 (Div. 2) E. Fire
http://codeforces.com/contest/864/problem/E 题意: 有一堆物品,每个物品有3个属性,需要的时间,失效的时间(一开始)和价值.只能一件一件的选择物品(即在选择 ...
- Codeforces#543 div2 A. Technogoblet of Fire(阅读理解)
题目链接:http://codeforces.com/problemset/problem/1121/A 真·阅读理解 题意就是 有n个人 pi表示他们的强度 si表示他们来自哪个学校 现在Arkad ...
- Codeforces Round #436 (Div. 2) E. Fire(dp 记录路径)
E. Fire time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- Codeforces Round #436 (Div. 2) E. Fire(背包+记录路径)
传送门 题意 给出n种物品,抢救第\(i\)种物品花费时间\(t_i\),价值\(p_i\),截止时间\(d_i\) 询问抢救的顺序及物品价值和最大值 分析 按\(d_i\)排序的目的是防止以下情况 ...
- Codeforces Global Round 3
Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...
随机推荐
- 《剑指offer》链表专题 (牛客10.23)
难度 题目 知识点 03. 返回链表的反序 vector 递归,C++ STL reverse() * 14. 链表中倒数第k个结点 指针操作 15. 反转链表 头插法,递归 16. 合并两个有序链表 ...
- 攻防世界WEB新手练习
0x01 view_source 0x02 get_post 这道题就是最基础的get和post请求的发送 flag:cyberpeace{b1e763710ff23f2acf16c2358d3132 ...
- jackson 实体转json 为NULL或者为空不参加序列化【转载】
原博客:https://www.cnblogs.com/yangy608/p/3936848.html 1.实体上 /** * 将该标记放在属性上,如果该属性为NULL则不参与序列化 * 如果放在类上 ...
- C++.控制台_界面颜色
1.c++中system(_color )怎样用?-CSDN论坛.html(https://bbs.csdn.net/topics/390758320) 2. 2.1. 颜色属性由两个十六进制数字指定 ...
- Hogan.js的使用
一个比较简单的前端模板引擎,参考一下两篇文件即可学会:https://www.cnblogs.com/zhangruiqi/p/8547268.htmlhttps://www.imooc.com/ar ...
- HBuilder git使用教程
1.插件安装 打开HBuilder,工具->插件安装. 等待安装,成功后提示重启后生效,立即重启. 2.在码云上新建一个项目,复制项目地址. 码云地址:https://gitee.com/ 3. ...
- 学习笔记:CentOS7学习之二十三: 跳出循环-shift参数左移-函数的使用
目录 学习笔记:CentOS7学习之二十三: 跳出循环-shift参数左移-函数的使用 23.1 跳出循环 23.1.1 break和continue 23.2 Shift参数左移指令 23.3 函数 ...
- webpack-dev-server 导致的 invalid host header
这几天做的一个项目,在这个项目的 js 方面,我将其分业务和功能的拆分成模块化,然后使用 webpack 来进行打包.(第一次在公司产品中使用 webpack) 然后使用了 webpack-dev-s ...
- [转帖]centos7设置CPU的运行频率为performance
centos7设置CPU的运行频率为performance http://www.512873.com/archives/612.html Publish: March 6, 2019 Categor ...
- 把Javascript 对象转换为键值对连接符字符串的方法总结
307down votefavorite 93 Do you know a fast and simple way to encode a Javascript Object into a strin ...