Submission #1087528

#TimeUsernameProblemLanguageResultExecution timeMemory
1087528Noname_1900Rice Hub (IOI11_ricehub)C++17
0 / 100
10 ms1884 KiB
#include "ricehub.h" #include<bits/stdc++.h> using namespace std; int besthub(int R, int L, int X[], long long B) { int nbRiz = R, maxPos = L; long long argent = B; //vector<pair<int, int>> int debTaille = 1, finTaille = nbRiz+1; while(debTaille < finTaille-1) { //cout << debTaille << " " << finTaille << " : "; int milieu = (debTaille+finTaille)/2; // cout << milieu << endl; int mediane = X[milieu/2]; bool marche = false; long long combienCout = 0; for(int i = 0; i < milieu; i++) { combienCout += abs(mediane-X[i]); } // cout << mediane<< " " << combienCout << endl; if(combienCout <= argent) { debTaille = milieu; continue; } for(int i = milieu; i < nbRiz; i++) { int ancMEdiane = mediane; combienCout -= abs(ancMEdiane-X[i-milieu]); mediane = X[(i+(i-milieu+1))/2]; combienCout += abs(mediane-X[i]); //combienCout += abs(ancMEdiane-mediane); // |c||||a|||||c| /// cout << mediane<< " " << combienCout << endl; if(combienCout <= argent) { debTaille = milieu; marche = true; break; } } if(!marche) finTaille = milieu; } return debTaille; }

Compilation message (stderr)

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:6:18: warning: unused variable 'maxPos' [-Wunused-variable]
    6 |   int nbRiz = R, maxPos = L;
      |                  ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...