QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#187433 | #6130. Plants vs. Zombies | microwave173 | WA | 1ms | 4204kb | C++14 | 1.4kb | 2023-09-24 17:16:38 | 2023-09-24 17:16:39 |
Judging History
answer
#include<iostream>
using namespace std;
int n, t;
long long m;
int a[100005];
void init(){
}
bool check(long long int x){
int p = 0;
long long int stp = 0;
long long int val[100005];
for(int i = 0;i < n;i++){
val[i] = 0;
}
while(1){
if(p >= n){ //小了或等于
return true;
}
long long int d = x - val[p];
if(d < 0) d = 0;
if(d == 0){
stp += 1;
p++;
continue;
}
long long int water_tim = d / a[p];
if(d % a[p] > 0) water_tim++;
val[p] += water_tim * a[p];
val[p + 1] += (water_tim - 1) * a[p + 1];
stp += 2 * water_tim - 1;
if(stp > m){ //大了
return false;
}
p++;
//cout << d << ' ' << stp << endl;
}
}
void solve(){
long long int l = 0;
long long int r = 1e17;
long long int mid;
while(r - l > 1){
//cout << l << ' ' << r << endl;
mid = (l + r + 1)/2;
bool flag = check(mid);
if(flag == false){
r = mid - 1;
}
else{
l = mid;
}
}
//cout << l << ' ' << r << endl;
cout << l << endl;
}
int main(){
cin >> t;
while(t--){
cin >> n >> m;
for(int i = 0;i < n;i++){
cin >> a[i];
}
solve();
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 4204kb
input:
2 4 8 3 2 6 6 3 9 10 10 1
output:
6 3
result:
wrong answer 2nd numbers differ - expected: '4', found: '3'