답안 #1087530

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087530 2024-09-12T21:04:24 Z Noname_1900 쌀 창고 (IOI11_ricehub) C++17
0 / 100
2 ms 348 KB
#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

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;
      |                  ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -