結果
| 問題 |
No.1008 Bench Craftsman
|
| コンテスト | |
| ユーザー |
jell
|
| 提出日時 | 2020-03-15 23:12:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 280 ms / 2,000 ms |
| コード長 | 1,998 bytes |
| コンパイル時間 | 2,514 ms |
| コンパイル使用メモリ | 151,648 KB |
| 最終ジャッジ日時 | 2025-01-09 07:11:22 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
コンパイルメッセージ
main.cpp:21:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
21 | main()
| ^~~~
ソースコード
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <bitset>
#include <functional>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <tuple>
#include <cassert>
#include <string>
using namespace std;
template <class T> void chmax(T &x, T y) {if(x<y) x=y;}
template <class T> void chmin(T &x, T y) {if(x>y) x=y;}
main()
{
ios::sync_with_stdio(false), cin.tie(nullptr);
int n,m; cin>>n>>m;
vector<int> a(n);
for(int &e:a) cin>>e;
vector<pair<int,int>> h(m);
for(auto &e:h)
{
int x,w; cin>>x>>w; --x;
e={x,w};
}
// binary search
long long ok=1e5+1;
long long ng=0;
while(ok-ng>1)
{
long long c=(ok+ng)/2;
vector<long long> b(n+1);
for(auto &e:h)
{
int x,w; tie(x,w)=e;
const int l=max(0LL,x-w/c);
const int r=x+w/c+1;
b[l+1]+=c;
b[x+1]-=c*2;
if(r<=n) b[r]+=c;
}
for(int i=0;i<n;++i)
{
b[i+1]+=b[i];
}
for(auto &e:h)
{
int x,w; tie(x,w)=e;
const int l=max(0LL,x-w/c);
const int r=x+w/c+1;
b[l]+=w-c*(x-l);
if(r<=n) b[r]-=w%c;
}
for(int i=0;i<n;++i)
{
b[i+1]+=b[i];
}
bool fail=0;
for(int i=0;i<n;++i)
{
if(b[i]>=a[i])
{
fail=1;
}
}
if(fail)
{
ng=c;
}
else
{
ok=c;
}
}
if(ng)
{
if(ok>1e5) cout << -1 << "\n";
else cout << ok << "\n";
}
else
{
long long ws=0;
for(auto &e:h)
{
ws+=e.second;
}
if(ws>=*min_element(begin(a),end(a)))
{
cout << 1 << "\n";
}
else
{
cout << 0 << "\n";
}
}
}
jell