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的更多相关文章

  1. codeforces#1148E. Earth Wind and Fire(贪心)

    题目链接: http://codeforces.com/contest/1148/problem/E 题意: 给出两个长度为$n$的序列,将第一个序列变成第二个序列,顺序不重要,只需要元素完全相同即可 ...

  2. 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 ...

  3. Codeforces 1148E Earth Wind and Fire

    分析 必要条件: ① $\sum_{i=1}^{n} s_i = \sum_{i=1}^{n} t_i$ 预处理: 将 $s, t$ 从小到大排序. 尝试一 首尾匹配.例子 s = 2, 2, 4, ...

  4. Earth Wind 一个查看全球风向的网站

    可以查看整个地球的全貌 ,还能定位你的位置,特别是动画挺有意思 网址:https://earth.nullschool.net/#current/wind/surface/level/orthogra ...

  5. Codeforces Round #436 (Div. 2) E. Fire

    http://codeforces.com/contest/864/problem/E 题意: 有一堆物品,每个物品有3个属性,需要的时间,失效的时间(一开始)和价值.只能一件一件的选择物品(即在选择 ...

  6. Codeforces#543 div2 A. Technogoblet of Fire(阅读理解)

    题目链接:http://codeforces.com/problemset/problem/1121/A 真·阅读理解 题意就是 有n个人 pi表示他们的强度 si表示他们来自哪个学校 现在Arkad ...

  7. 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 ...

  8. Codeforces Round #436 (Div. 2) E. Fire(背包+记录路径)

    传送门 题意 给出n种物品,抢救第\(i\)种物品花费时间\(t_i\),价值\(p_i\),截止时间\(d_i\) 询问抢救的顺序及物品价值和最大值 分析 按\(d_i\)排序的目的是防止以下情况 ...

  9. Codeforces Global Round 3

    Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...

随机推荐

  1. ORACLE-JDK非收费版本下载链接

    这个链接下可以下载oracleJDK的所有版本 https://www.oracle.com/technetwork/java/javase/archive-139210.html 其中jdk192之 ...

  2. 小技巧 Mongodb 动态查询 除去 _class 条件

    最近在做通用模板标准示例项目,在使用  spring data jpa  Mongodb 的时候,动态查询会代入 _class条件. 为什么这么做其实也很好理解,写入数据库的数据中是有这个字段的.接受 ...

  3. 【ARM-Linux开发】Linux下查看机器的CPU负载

    负载(load)是Linux机器的一个重要指标,直观了反应了机器当前的状态.如果机器负载过高,那么对机器的操作将难以进行. Linux的负载高,主要是由于CPU使用.内存使用.IO消耗三部分构成.任意 ...

  4. VS.左侧_蓝黄绿_竖线

    1.vs2013中,写代码中,旁边会出现蓝色或者黄色的线,请问是什么意思?求大神告知_百度知道.html(https://zhidao.baidu.com/question/1862841692529 ...

  5. jquery中 $.expr使用实例介绍

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. 鼠标拖拉div宽度

    先看效果 先进入页面 当鼠标停留在中间div时,鼠标变成双箭头 点击拖拉 往右边拉 往最左边拉 代码 <!DOCTYPE html> <html> <head> & ...

  7. ssh速度慢

    原因:DNS解析默认开了 解决方法: vi /etc/ssh/sshd_config, 将#UseDNS yes 改为 : UseDNS no 然后重启ssh服务即可.   PS: 其实不好,因为毕竟 ...

  8. 异构平台mysql-oracle(ogg)安装部署

      如图所示:源端采用Mysql库,目标端采用Oracle库 一.OGG安装配置(源端) 1.OGG下载 https://edelivery.oracle.com/EPD/Download/get_f ...

  9. python在windows和linux下的安装和配置

    一.windows下安装python3.6 安装编辑器:Ecplise+pydev插件 Eclipse是写JAVA的IDE, 这样就可以通用了,学习代价小.  学会了Eclipse, 以后写Pytho ...

  10. (八)springMvc 的参数绑定

    参数绑定 将客户端传来的 key/value 数据,绑定到 Controller 参数的过程 : 这一过程发生在调用 处理器适配器 的时候,spring 会去调用 参数绑定 组件,我使用的版本(4.5 ...