結果
| 問題 |
No.1008 Bench Craftsman
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2020-03-06 23:01:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,683 bytes |
| コンパイル時間 | 2,254 ms |
| コンパイル使用メモリ | 208,524 KB |
| 最終ジャッジ日時 | 2025-01-09 05:30:15 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 WA * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | scanf("%lld",&a[i]);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:19:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
19 | scanf("%lld %lld",&V[i].first,&V[i].second);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000
int main(){
int N,M;
cin>>N>>M;
vector<long long> a(N);
for(int i=0;i<N;i++){
scanf("%lld",&a[i]);
}
vector<pair<long long,long long>> V(M);
for(int i=0;i<M;i++){
scanf("%lld %lld",&V[i].first,&V[i].second);
V[i].first--;
}
long long ok = 100005;
long long ng = -1;
while(ok-ng>1){
long long c = (ok+ng)/2;
vector<vector<int>> add(N,vector<int>()),del(N,vector<int>());
for(int i=0;i<M;i++){
if(c==0){
add[0].push_back(i);
continue;
}
long long x = (V[i].second+c-1)/c;
x--;
add[max(V[i].first-x,0LL)].push_back(i);
del[min(V[i].first+x,(long long)N-1)].push_back(i);
}
bool f = true;
long long sum = 0;
multiset<int> M1,M2;
for(int i=0;i<N;i++){
sum -= c*M1.size();
sum += c*M2.size();
int C = M2.count(i);
M2.erase(i);
for(int j=0;j<C;j++)M1.insert(i);
for(int j=0;j<add[i].size();j++){
int ind = add[i][j];
if(i>=V[ind].first){
M1.insert(ind);
}
else{
M2.insert(ind);
}
sum += V[ind].second - abs(i-V[ind].first)*c;
}
/*
if(c==1){
cout<<i<<','<<sum<<endl;
}*/
if(a[i]<=sum){
f=false;
break;
}
for(int j=0;j<del[i].size();j++){
//if(c==1)cout<<i<<endl;
int ind = del[i][j];
if(M1.count(ind)){
M1.erase(M1.lower_bound(ind));
}
else{
M2.erase(M2.lower_bound(ind));
}
sum -= V[ind].second - abs(i-V[ind].first)*c;
}
}
if(f)ok = c;
else ng = c;
}
if(ok==100005)ok=-1;
cout<<ok<<endl;
return 0;
}
沙耶花