Submission #114520

# Submission time Handle Problem Language Result Execution time Memory
114520 2019-06-01T15:07:28 Z mosesmayer Rice Hub (IOI11_ricehub) C++17
100 / 100
22 ms 2660 KB
#include "ricehub.h"
#include <algorithm>

typedef long long LL;
LL all[100005];
int besthub(int R, int L, int X[], long long B)
{
  for (int i=1; i <= R; i++) all[i] = X[i-1];
  std::sort(all+1,all+R+1);
  LL left = 1, right = 1, mx = -1, totalSum = 0;
  LL median = 1, newmedian;
  LL cost = 0;
  LL mxInterval = -1;
  while (right <= R){
    totalSum += all[right];
    int range = (right-left+1);
    newmedian = (left+right)>>1;
    cost += all[right]-all[median];
    if (newmedian > median){
      while (median < newmedian){
        int change = median - left + 1 - (right - median);
        cost += 1LL * change * (all[median+1]-all[median]);
        median++;
      }
    }
    while (cost > B){
      left++;
      cost -= all[median] - all[left-1];
      while (median < ((left+right)>>1)){
        int change = median - left + 1 - (right - median);
        cost += 1LL * change * (all[median+1]-all[median]);
        median++;
      }
    }
    mxInterval = std::max(mxInterval, right - left + 1);
    right++;
  }
  return mxInterval;

  //return R;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:16:9: warning: unused variable 'range' [-Wunused-variable]
     int range = (right-left+1);
         ^~~~~
ricehub.cpp:10:27: warning: unused variable 'mx' [-Wunused-variable]
   LL left = 1, right = 1, mx = -1, totalSum = 0;
                           ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 2 ms 392 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 4 ms 428 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 3 ms 428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 768 KB Output is correct
2 Correct 22 ms 640 KB Output is correct
3 Correct 17 ms 2660 KB Output is correct
4 Correct 16 ms 2560 KB Output is correct
5 Correct 8 ms 1280 KB Output is correct
6 Correct 8 ms 1280 KB Output is correct
7 Correct 14 ms 2304 KB Output is correct
8 Correct 15 ms 2304 KB Output is correct
9 Correct 8 ms 1280 KB Output is correct
10 Correct 8 ms 1280 KB Output is correct
11 Correct 18 ms 2552 KB Output is correct
12 Correct 19 ms 2524 KB Output is correct
13 Correct 8 ms 1280 KB Output is correct
14 Correct 10 ms 1408 KB Output is correct
15 Correct 14 ms 2048 KB Output is correct
16 Correct 14 ms 1920 KB Output is correct
17 Correct 16 ms 2304 KB Output is correct
18 Correct 16 ms 2304 KB Output is correct
19 Correct 18 ms 2432 KB Output is correct
20 Correct 17 ms 2432 KB Output is correct