Sat, 09 Feb 2019 21:51:04 GMT

master
大蒟蒻 7 years ago
parent 5f59690215
commit 903dd2ff5e

@ -57,3 +57,9 @@ multiset.upper_bound()
### M - Alice and Bob
multiset搞一下又忘记clear了
### N - Moo University - Financial Aid
按成绩排序后用两个堆分别维护每头牛前后花钱最少的`n/2`头牛,逆序扫一遍即可。
> 辣鸡poj不让用`bits/stdc++.h`

@ -2,9 +2,9 @@
cmake_minimum_required(VERSION 3.0)
set(CMAKE_CXX_STANDARD 17)
if(MSVC)
add_compile_options("/Zc:__cplusplus")
add_compile_options("/Zc:__cplusplus" "/wd6031")
endif()
include_directories("C:\\Programs\\GCC\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include\\c++\\x86_64-w64-mingw32")
include_directories("C:\\Users\\Administrator\\AppData\\Local\\Programs\\MSYS2\\mingw64\\include\\c++\\8.2.1\\x86_64-w64-mingw32")
add_executable(A A.cpp)
add_executable(B B.cpp)
add_executable(C C.cpp)

@ -1,8 +1,46 @@
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
//#include <bits/stdc++.h>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <utility>
using namespace std;
const int N = 1e5 + 50;
pair<int, int> a[N];
int b[N];
int main()
{
int n, c, f;
scanf("%d%d%d", &n, &c, &f);
for (int i = 0; i < c; i++)
scanf("%d%d", &a[i].first, &a[i].second);
sort(a, a + c);
priority_queue<int> h1, h2;
for (int i = 0, x = 0; i < c; i++)
{
if (i >= (n >> 1))
{
b[i] += x;
if (a[i].second >= h1.top()) continue;
x -= h1.top(), h1.pop();
}
x += a[i].second, h1.push(a[i].second);
}
for (int i = c - 1, x = 0; i >= 0; i--)
{
if ((c - i - 1) >= (n >> 1))
{
b[i] += x;
if (a[i].second >= h2.top()) continue;
x -= h2.top(), h2.pop();
}
x += a[i].second, h2.push(a[i].second);
}
int ans = -1;
for (int i = c - 1 - (n >> 1); i >= (n >> 1) && ans == -1; i--)
if (b[i] + a[i].second <= f)
ans = a[i].first;
printf("%d", ans);
return 0;
}
}
Loading…
Cancel
Save