2018湘潭校赛 E-吃货

xiaoxiao2021-02-28  35

吃货

题目描述

作为一个标准的吃货,mostshy又打算去联建商业街觅食了。 混迹于商业街已久,mostshy已经知道了商业街的所有美食与其价格,而且他给每种美食都赋予了一个美味度,美味度越高表示他越喜爱这种美食。 mostshy想知道,假如带t元去商业街,只能吃一种食物,能够品味到的美食的美味度最高是多少?

输入

第一行是一个整数T(1 ≤ T ≤ 10),表示样例的个数。 以后每个样例第一行是两个整数n,m(1 ≤ n,m ≤ 30000),表示美食的种类数与查询的次数。 接下来n行,每行两个整数分别表示第i种美食的价格与美味度di,ci (1 ≤ di,ci ≤ 109)。 接下来m行,每行一个整数表示mostshy带t(1 ≤ t ≤ 109)元去商业街觅食。

输出

每个查询输出一行,一个整数,表示带t元去商业街能够品味到美食的最高美味度是多少,如果不存在这样的美食,输出0。

样例

输入 1 3 3 1 100 10 1000 1000000000 1001 9 10 1000000000 输出 100 1000 1001 说明 大量的输入输出,请使用C风格的输入输出。

题意

数据这么大当然要进行二分了,, 预处理没搞定 一直wa,,

AC代码

#include <bits/stdc++.h> using namespace std; #define LL long long #define CLR(a,b) memset(a,(b),sizeof(a)) const int MAXN = 3e4+10; int x; struct node { int c, w; bool operator <(const node &r)const { return c < r.c; } }p[MAXN]; bool check(int i) { return p[i].c <= x; } int main() { // ios::sync_with_stdio(false); int T; scanf("%d",&T); while(T--) { int n, m; scanf("%d%d",&n,&m); for(int i = 1; i <= n; i++) { scanf("%d%d",&p[i].c,&p[i].w); } sort(p+1,p+n+1); for(int i = 1; i < n; i++) { if(p[i+1].w < p[i].w) p[i+1].w = p[i].w; } while(m--) { int ans = 0; scanf("%d",&x); int l = 1, r = n; while(l <= r) { int mid = l+(r-l)/2; if(check(mid)) ans = p[mid].w, l = mid+1; else r = mid-1; } printf("%d\n",ans); } } return 0; }
转载请注明原文地址: https://www.6miu.com/read-2629402.html

最新回复(0)