#include<bits/stdc++.h>
using namespace std;
#define int long long
const int TAILLE_MAX=100*1000+5,INFINI=1000*1000*1000;
int nbVal,posInit,tempsInit;
int val[TAILLE_MAX];
vector<pair<int,int>> decompo(vector<int> v) {
vector<pair<int,int>> ans;
int somCour=0,minSom=0,taille=0;
for (int i:v) {
//cout<<i<<" ";
somCour+=i;
minSom=min(minSom,somCour);
taille++;
if (somCour>=0) {
ans.push_back({somCour,minSom});
taille=0;
somCour=0;
minSom=0;
}
}
if (taille>0) {
ans.push_back({somCour,minSom});
}
/*cout<<" : ";
for (auto i:ans) {
cout<<i.first<<" "<<i.second<<" ";
}
cout<<endl;*/
reverse(ans.begin(),ans.end());
return ans;
}
bool calc(vector<pair<int,int>> bonGau,vector<pair<int,int>> bonDro) {
int somCour=0;
while ((!bonGau.empty() and somCour+bonGau.back().second>=0) or (!bonDro.empty() and somCour+bonDro.back().second>=0)) {
if (!bonGau.empty() and somCour+bonGau.back().second>=0 and bonGau.back().first>=0) {
somCour+=bonGau.back().first;
bonGau.pop_back();
}
else if (!bonDro.empty() and somCour+bonDro.back().second>=0 and bonDro.back().first>=0) {
somCour+=bonDro.back().first;
bonDro.pop_back();
}
else if (!bonGau.empty() and somCour+bonGau.back().second>=0) {
somCour+=bonGau.back().first;
bonGau.pop_back();
}
else {
somCour+=bonDro.back().first;
bonDro.pop_back();
}
}
return (bonGau.empty() and bonDro.empty());
}
bool verif(int temps) {
//cout<<temps<<endl;
vector<int> listeGau,listeDro;
for (int i=posInit;i>1;i--) {
listeGau.push_back(2*temps-val[i]+val[i-1]);
}
for (int i=posInit+1;i<=nbVal;i++) {
listeDro.push_back(2*temps-val[i]+val[i-1]);
}
vector<pair<int,int>> bonGau=decompo(listeGau),bonDro=decompo(listeDro);
if (calc(bonGau,bonDro)!=calc(bonDro,bonGau)) {
while (1>0) {
listeGau.pop_back();
}
}
return (calc(bonGau,bonDro) or calc(bonDro,bonGau));
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>nbVal>>posInit>>tempsInit;
for (int i=1;i<=nbVal;i++) {
cin>>val[i];
}
int deb=0,fin=INFINI,mid;
while (deb!=fin) {
mid=(deb+fin)/2;
if (verif(mid)) {
fin=mid;
}
else {
deb=mid+1;
}
}
cout<<(deb+tempsInit-1)/tempsInit<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Execution timed out |
2097 ms |
348 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Execution timed out |
2097 ms |
348 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Execution timed out |
2097 ms |
348 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |