Submission #245142

# Submission time Handle Problem Language Result Execution time Memory
245142 2020-07-05T14:56:08 Z A02 Rice Hub (IOI11_ricehub) C++11
100 / 100
24 ms 768 KB
#include "ricehub.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <fstream>

using namespace std;
int besthub(int R, int L, int X[], long long B)
{

    long long left_best = 0;
    long long right_best = 0;
    long long current_cost = 0;
    long long current_field = 0;
    long long current_max = 1;

    while (current_cost <= B){

        if (right_best == R - 1){
            break;
        }

        if (X[right_best + 1] - X[0] + current_cost > B){
            break;
        }

        right_best++;
        current_cost += X[right_best] - X[0];
        current_max++;
    }

    long long best = current_max;

    while (current_field != R - 1){

        long long distance_moved = X[current_field + 1] - X[current_field];

        long long to_right = right_best - current_field;
        long long to_left =  current_field - left_best + 1;

        current_cost += to_left * distance_moved;
        current_cost -= to_right * distance_moved;

        if (current_field == right_best){
            right_best++;
            current_max++;
        }
        current_field++;

        while (current_cost < B && left_best != 0){
            current_cost += (X[current_field] - X[left_best - 1]);
            current_max++;
            left_best--;
        }
        while (current_cost > B){
            current_cost -= (X[current_field] - X[left_best]);
            current_max--;
            left_best++;
        }


        while (right_best != R - 1){

            if (current_cost + X[right_best + 1] - X[current_field] <= B){
                current_cost += (X[right_best + 1] - X[current_field]);
                right_best++;
                current_max++;
            } else {
                if (X[current_field] - X[left_best] > X[right_best] - X[current_field]){
                    current_cost -= (X[current_field] - X[left_best]);
                    current_cost += (X[right_best + 1] - X[current_field]);
                    right_best++;
                    left_best++;
                }  else {
                break;
            }
            }

        }

        best = max(current_max, best);
    }

    //cout << X[0] << ' ' << X[1] << ' ' << X[2] << endl;
    //cout << best << ' ' << current_cost << ' ' << right_best << ' ' << B <<  endl;
    return best;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 256 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 256 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 256 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 5 ms 256 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
3 Correct 22 ms 768 KB Output is correct
4 Correct 22 ms 768 KB Output is correct
5 Correct 11 ms 512 KB Output is correct
6 Correct 11 ms 512 KB Output is correct
7 Correct 19 ms 768 KB Output is correct
8 Correct 19 ms 768 KB Output is correct
9 Correct 12 ms 512 KB Output is correct
10 Correct 12 ms 512 KB Output is correct
11 Correct 22 ms 768 KB Output is correct
12 Correct 24 ms 768 KB Output is correct
13 Correct 13 ms 512 KB Output is correct
14 Correct 14 ms 512 KB Output is correct
15 Correct 18 ms 640 KB Output is correct
16 Correct 19 ms 640 KB Output is correct
17 Correct 22 ms 640 KB Output is correct
18 Correct 21 ms 640 KB Output is correct
19 Correct 22 ms 768 KB Output is correct
20 Correct 23 ms 640 KB Output is correct