n 件T恤。第 i 件T恤的价格为 pi 。每个T恤有两面,第 i 件T恤正面颜色为 ai ,反面颜色为 bi

m 个人想买T恤,每个人都恰好买一件。第 j 个人最喜欢颜色 cj

一个人会选择买一件至少有一面颜色为他喜欢的颜色的,最便宜的T恤。如果没有合法的T恤,则不买。这些人按照给定的顺序来购买。

你的任务是求出每个人会花多少钱。

Input

第一行包含一个整数 n (1 ≤ n ≤ 200 000) — 表示T恤的数量。

之后一行为 p1, p2, ..., pn (1 ≤ pi ≤ 1 000 000 000), pi 表示第 i 件T恤的价格。

之后一行为 a1, a2, ..., an (1 ≤ ai ≤ 3), ai 表示第 i 件T恤正面的颜色。

之后一行为 b1, b2, ..., bn (1 ≤ bi ≤ 3), bi 表示第 i 件T恤背面的颜色。

之后一行包含一个整数 m (1 ≤ m ≤ 200 000) — 表示消费者人数。

之后一行为 c1, c2, ..., cm (1 ≤ cj ≤ 3), where cj表示第 j 个消费者最喜欢的颜色。这些消费者会按输入的顺序一个一个来购买。

Output

一行 m 个数 — 第 j 个数表示第 j-th buyer will buy. If the j 个消费者需要花的钱数。如果不购买,输出 -1。

Example

Input
5
300 200 400 500 911
1 2 1 2 3
2 1 3 2 1
6
2 3 1 2 1 1
Output
200 400 300 500 911 -1 
Input
2
1000000000 1
1 1
1 2
2
2 1
Output
1 1000000000 

由于题目说了,每件衣服的价格都一定不同,所以可以用set。
c++ stl容器set成员函数:insert()--在集合中插入元素。
{
  Extends the container by inserting new elements, effectively increasing the container size by the number of elements inserted.
  //通过插入新元素来扩展容器,通过插入的元素数量有效地增加容器大小。
  Because elements in a set are
unique, the insertion operation checks whether each inserted element is
equivalent to an element already in the container, and if so, the
element is not inserted, returning an iterator to this existing element
(if the function returns a value).
  //因为集合中的元素是唯一的,所以插入操作检查每个插入的元素是否等同于已经在容器中的元素,如果是,则不插入元素,将迭代器返回到此现有元素(如果函数有返回值)。
  Internally, set containers keep all their elements sorted following the criterion specified by its comparison object. The elements are always inserted in its respective position following this ordering.
  //在内部,设置容器使其所有元素按照其比较对象指定的标准进行排序。 这些元件总是插入其相应的位置。
}
c++ stl容器set成员函数:empty()--如果集合为空,返回true。
c++ stl容器set成员函数:begin()--返回指向第一个元素的迭代器。
c++ stl容器set成员函数:erase()--删除集合中的元素。
#include<bits/stdc++.h>
using namespace std;
int shirts[200050];
int main()
{
int n;
cin>>n;
set<int> cost[4];
for(int i=0;i<n;i++)
cin>>shirts[i];
for(int i=0;i<2*n;i++)
{
int input;
cin>>input;
cost[input].insert(shirts[i%n]);
}
int m;
cin>>m;
while(m--)
{
int color;
cin>>color;
if(cost[color].empty()) cout<<"-1 ";
else
{
int ans= *cost[color].begin();
cout<<ans<<" ";
for(int i=1;i<=3;i++)
cost[i].erase(ans);
}
}
cout<<endl;
return 0;
}

CodeForce-799B T-shirt buying (STL_set)的更多相关文章

  1. 【codeforces 799B】T-shirt buying

    [题目链接]:http://codeforces.com/contest/799/problem/B [题意] 告诉你每个人喜欢的衣服的颜色; 然后告诉你每件衣服的正面和背面的颜色以及它的价格; 只要 ...

  2. T-shirt buying CodeForces - 799B (小根堆+STL)

    题目链接 思路: 由于题目说了只有1,2,3,三种色号的衣服,然后开三个对应色号的小根堆, 我是根据pair<int,int> 创建了一个以价格小的优先的优先队列. pair中的另外一个i ...

  3. CF 799B T-shirt buying

    一道超级水的练习STL的题目 题目大意:有\(n\)件T恤,每件T恤都分别有价格(每件衣服的价格不重复).前面的颜色.背部的颜色三种属性.接下来有\(m\)个人每个人都有一种喜欢的颜色,他们按先后顺序 ...

  4. Codeforces 799B - T-shirt buying(STL)

    题目链接:http://codeforces.com/problemset/problem/799/B 题目大意:有n件T恤,每件T体恤都分别有价格(每件衣服的价格不重复).前面的颜色.背部的颜色三种 ...

  5. CodeForces - 799B T-shirt buying 【贪心】

    题目链接 http://codeforces.com/problemset/problem/799/B 题意 给出N件衣服 pi 表示 第i件衣服的价格 ai 表示 第i件衣服的前面的颜色 bi 表示 ...

  6. ACM BUYING FEED

    BUYING FEED 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 Farmer John needs to travel to town to pick up ...

  7. Codeforce - Street Lamps

    Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...

  8. [BZOJ1618][Usaco2008 Nov]Buying Hay 购买干草

    [BZOJ1618][Usaco2008 Nov]Buying Hay 购买干草 试题描述 约翰的干草库存已经告罄,他打算为奶牛们采购H(1≤H≤50000)磅干草. 他知道N(1≤N≤100)个干草 ...

  9. Codeforce Round #216 Div2

    e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头 ...

随机推荐

  1. Linux应用程序安装方法

    一.linux应用程序基础 1.1.应用程序与系统命令的关系 1.2.典型应用程序的目录结构 1.3.常见的软件包封装类型 二.RPM包管理工具 2.1.RPM软件包管理器Red-Hat Packag ...

  2. Linux之cat tail less常见用法

    1.cat 通常查找出错误日志 cat error.log | grep 'foo' , 这时候我们还有个需求就是输出当前这个日志的前后几行: cat error.log | grep -C 10 ' ...

  3. Python - typing 模块 —— NewType

    前言 typing 是在 python 3.5 才有的模块 前置学习 Python 类型提示:https://www.cnblogs.com/poloyy/p/15145380.html 常用类型提示 ...

  4. 006 PCI总线的桥与配置(一)

    在PCI体系结构中,含有两类桥片,一个是HOST主桥,另一个是PCI桥.在每一个PCI设备中(包括PCI桥)都含有一个配置空间.这个配置空间由HOST主桥管理,而PCI桥可以转发来自HOST主桥的配置 ...

  5. SpringBoot跨域

    第一种方法 在Controller类或方法上加上@CrossOrigin元注解 package com.wzq.test.action; import com.wzq.utils.BatchDownF ...

  6. wpf 自定义 RadioButton.

    <Style TargetType="RadioButton" x:Key="nav"> <Setter Property="Tem ...

  7. jquery 操作checkbox是否选中的正确方法

    对于checkbox,若要选中,需要用jquery的prop()方法,不要用attr(). <input type="checkbox" id="slide_che ...

  8. [SWMM]汇水区特征宽度的计算方法

    SWMM模型产流计算中,有一个比较重要的参数就是子汇水区的特征宽度(width),这个参数对地表汇流时间和峰值有一定的影响.子汇水区特征宽度的计算方法有很多,这里介绍比较常用的两种: (1)采用面积除 ...

  9. Executor执行器

    Executors: CachedThreadPool  将为每个任务创建一个线程. public class CachedThreadPool { public static void main(S ...

  10. 使用dom4j工具:获得文本内容(四)

    package dom4j_read; import java.io.File; import org.dom4j.Document; import org.dom4j.Element; import ...