Can't test the solution at internship, but I suspect it should be close to correct

This commit is contained in:
Philippe Zwietering
2021-12-08 15:31:53 +01:00
parent 93c452fdfa
commit cb14a763e1

View File

@@ -2,8 +2,55 @@
using namespace std; using namespace std;
void test_case(int tc){ typedef long long ll;
vector<ll> attacks;
ll damage(ll k){
ll result = k;
for(size_t i = 0; i < attacks.size() - 1; ++i){
result += min(k, attacks[i+1] - attacks[i]);
}
return result;
}
void test_case(int tc){
cout << "test";
int n;
ll h;
cin >> n >> h;
attacks.clear();
attacks.reserve(n);
for(int i = 0; i < n; ++i){
cin >> attacks[i];
}
ll lower = 1, upper = 1e18;
ll middle = (lower + upper) / 2;
ll dx = middle - lower;
ll k;
while(dx > 0){
k = damage(middle);
cout << k << " ";
if(k == h){
break;
} else if(k < h){
lower = middle + 1;
} else{
upper = middle;
}
middle = (lower + upper) / 2;
dx = middle - lower;
}
cout << '\n' << k << '\n';
} }