結果
| 問題 |
No.1008 Bench Craftsman
|
| コンテスト | |
| ユーザー |
ゆきのん
|
| 提出日時 | 2020-03-10 06:16:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,718 bytes |
| コンパイル時間 | 1,696 ms |
| コンパイル使用メモリ | 176,040 KB |
| 実行使用メモリ | 17,408 KB |
| 最終ジャッジ日時 | 2024-11-15 23:04:46 |
| 合計ジャッジ時間 | 13,878 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 RE * 1 |
| other | AC * 10 WA * 12 RE * 5 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};
int main(){
int n,m;cin >> n >> m;
vector<LL> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<LL> x(m),w(m);
bool fl = true;
for (int i = 0; i < m; i++) {
cin >> x[i] >> w[i];
x[i]--;
if(a[x[i]] <= w[i]){
fl = false;
}
}
if(not fl){
puts("-1");
}
else if(*min_element(ALL(a)) > accumulate(ALL(w),0)){
puts("0");
}
else{
int l = 0,r = INF;
while(abs(r - l) > 1){
LL c = (r + l) / 2;
vector<vector<LL>> imosr(n+1,vector<LL> (3,0));
vector<vector<LL>> imosl(n+1,vector<LL> (3,0));
vector<LL> v(n,0);
for (int i = 0; i < n; i++) {
LL k = w[i] / c;
imosr[x[i]][2] += w[i];
imosr[x[i]+1][0] -= c;
if(x[i] + k < n){
imosr[x[i]+k+1][0] += c;
imosr[x[i]+k+1][2] -= w[i]%c;
}
imosl[x[i]][2] += w[i];
if(x[i] - 1 >= 0) imosl[x[i]-1][0] -= c;
if(x[i] - k - 1 >= 0){
imosl[x[i]-k-1][0] += c;
imosl[x[i]-k-1][2] -= w[i]%c;
}
v[x[i]] -= w[i];
}
for (int i = 0; i < n; i++) {
for (int j = 1; j < 3; j++) {
imosr[i][j] += imosr[i][j-1];
if(i) imosr[i][j] += imosr[i-1][j];
}
}
for (int i = n-1; i >= 0; i--) {
for (int j = 1; j < 3; j++) {
imosl[i][j] += imosl[i][j-1];
imosl[i][j] += imosl[i+1][j];
}
}
for (int i = 0; i < n; i++) {
v[i] += imosr[i][2] + imosl[i][2];
}
bool f = true;
for (int i = 0; i < n; i++) {
if(a[i] <= v[i]) f = false;
}
if(f) r = c;
else l = c;
}
cout << r << endl;
}
return 0;
}
ゆきのん