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. Map对象,Set对象使用(2)

    今天重点见一下Set Set 在我印象里它主要就是去重,Set 是一个值的集合,这个集合中所有的值仅出现一次 Set 属性size:和Map的size一样,返回成员的总数 Set的方法: Set.pr ...

  2. shell学习笔记2-find和xargs

    1,find命令形式 find pathname -options [-print - exec -ok] pathname find命令所查找的目录路径.. 表示当前目录,/表示系统根路径 -pri ...

  3. 【VS开发】#pragma预处理命令

    #pragma预处理命令 #pragma可以说是C++中最复杂的预处理指令了,下面是最常用的几个#pragma指令: #pragma comment(lib,"XXX.lib") ...

  4. POJ2594 Treasure Exploration【DAG有向图可相交的最小路径覆盖】

    题目链接:http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K T ...

  5. RPA自定义脚本打开文件夹

    import os import subprocess from rpa.web.common.utils import convert_2_unicode def startfile(filenam ...

  6. 编写函数实现strcmp( )函数功能

    strcmp(字符串1,字符串2) 作用是比较字符串1和字符串2.两个字符串从左至右逐个字符比较(按照字符的ASCII码值的大小)(即减法比较),直到字符不同或者遇见’\0’为止 如果全部字符都相同, ...

  7. Elastic Search快速上手(4):细节补充

    模糊搜索 可以进行模糊搜索: GET job/type1/_search { "query":{ "fuzzy":{ "title":{ & ...

  8. c#将电脑时间同步到网络时间

    最近遇到个项目,需要控制软件使用时间,由于电脑不联网可以修改时间,故需要联网使电脑同步网络时间 网上寻找了很多解决方案,代码如下: //Forproc_Win32.cs//对常用Win32 API函数 ...

  9. 手写map, filter函数

    function map(arr, fn) { let newArr = []; for (let i = 0; i < arr.length; i++) { newArr[i] = fn(ar ...

  10. 调用打码平台api获取验证码 (C#版)

    一.打码平台很多,这里选择两个:联众和斐斐 联众开发文档: https://www.jsdati.com/docs/guide 斐斐开发文档: http://docs.fateadm.com/web/ ...