Submission #1087530

#TimeUsernameProblemLanguageResultExecution timeMemory
1087530Noname_1900Rice Hub (IOI11_ricehub)C++17
0 / 100
2 ms348 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; mediane = X[(i+(i-milieu+1))/2]; combienCout -= abs(mediane-X[i-milieu]); 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:31:13: warning: unused variable 'ancMEdiane' [-Wunused-variable]
   31 |         int ancMEdiane = mediane;
      |             ^~~~~~~~~~
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...