結果
| 問題 |
No.1008 Bench Craftsman
|
| コンテスト | |
| ユーザー |
kotamanegi
|
| 提出日時 | 2020-03-06 22:29:05 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 438 ms / 2,000 ms |
| コード長 | 2,704 bytes |
| コンパイル時間 | 1,946 ms |
| コンパイル使用メモリ | 163,712 KB |
| 実行使用メモリ | 12,676 KB |
| 最終ジャッジ日時 | 2024-11-30 16:52:01 |
| 合計ジャッジ時間 | 10,165 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
コンパイルメッセージ
main.cpp:2:18: warning: '#pragma comment linker' ignored [-Wignored-pragmas]
2 | #pragma comment (linker, "/STACK:526000000")
| ^
1 warning generated.
ソースコード
#define _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")
#include "bits/stdc++.h"
using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()
void init() {
iostream::sync_with_stdio(false);
cout << fixed << setprecision(20);
}
#define int ll
vector<int> inputs;
vector<int> mans[200000];
int n, m;
int check(int border) {
vector<int> color;
REP(i, n) {
color.push_back(0);
}
{
priority_queue<pair<int, int>> next;
int cnt = 0;
int now = 0;
for (int q = n - 1; q >= 0; --q) {
for (auto x : mans[q]) {
next.push(mp(q - (x+border) / border, x % border));
now += x + border;
cnt++;
}
while (next.empty() == false&&next.top().first == q) {
cnt--;
now -= next.top().second;
next.pop();
}
now -= cnt * border;
color[q] += now;
}
}
{
priority_queue<pair<int, int>> next;
int cnt = 0;
int now = 0;
for (int q = 1; q < n; ++q) {
for (auto x : mans[q-1]) {
next.push(mp(-((q-1) + (x + border ) / border), x % border));
now += x;
cnt++;
}
while (next.empty() == false&&next.top().first == -q) {
cnt--;
now -= next.top().second;
next.pop();
}
now -= cnt * border;
color[q] += now;
}
}
REP(i, n) {
if (inputs[i] <= color[i]) return 0;
}
return 1;
}
void solve() {
cin >> n >> m;
REP(i, n) {
int a;
cin >> a;
inputs.push_back(a);
}
int hoge = 0;
REP(i, m) {
int a, b;
cin >> a >> b;
a--;
mans[a].push_back(b);
hoge += b;
}
//check(2);
int ok = 1;
REP(i, inputs.size()) {
if (hoge >= inputs[i]) {
ok = 0;
}
}
if (ok == 1) {
cout << 0 << endl;
return;
}
int bot = 1e9;
int top = 0;
while (bot - top > 1) {
int mid = (top + bot) / 2;
if (check(mid)) {
bot = mid;
}
else {
top = mid;
}
}
if (bot == 1e9) bot = -1;
cout << bot << endl;
}
#undef int
int main() {
init();
solve();
}
kotamanegi