Submission #485231

# Submission time Handle Problem Language Result Execution time Memory
485231 2021-11-06T15:34:43 Z chungdinh Rice Hub (IOI11_ricehub) C++17
Compilation error
0 ms 0 KB
#include <cstdio>
#include <string>
#include <queue>
#include <iostream>

using namespace std;

#define endl "\n"
#define cntbit(x) __builtin_popcount(x)
#define on(b, x) (b & (1 << x))
#define all(x) x.begin(), x.end()
#define gcd __gcd
#define ll long long
#define ii pair<int, int>

#define cost(l, r) a[r] - a[l]

const int N = 3e3 + 5;
const ll MOD = 998244353;
const int iINF = 1e9;
const ll INF = 1e18;

int n;
ll l, b;
ll a[N];

int main() {
    #ifdef CHUNGDINH
    freopen("main.inp", "r", stdin);
    #endif

    scanf("%d%lld%lld",&n,&l,&b);
    for (int i = 0; i < n; i++) scanf("%lld", a + i);

    ll res = 0;

    for (int i = 0; i < n; i++) {
        int l = i - 1, r = i + 1;

        ll subres = 0;
        ll left = b;

        while (l >= 0 || r <= n - 1) {
            if (l < 0) {
                if (cost(i, r) > left) break;
                subres++;
                left -= cost(i, r);
                r++;
            } else if (r > n - 1) {
                if (cost(l, i) > left) break;
                subres++;
                left -= cost(l, i);
                l--;
            } else {
                ll tt = min(cost(l, i), cost(i, r));
                if (tt > left) break;

                if (cost(l, i) < cost(i, r)) {
                    left -= cost(l, i);
                    l--;
                } else {
                    left -= cost(i, r);
                    r++;
                }
                subres++;
            }
        }

        res = max(res, subres + 1);
    }

    printf("%lld", res);
}

Compilation message

ricehub.cpp: In function 'int main()':
ricehub.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     scanf("%d%lld%lld",&n,&l,&b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
ricehub.cpp:33:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     for (int i = 0; i < n; i++) scanf("%lld", a + i);
      |                                 ~~~~~^~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccWmytNc.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cczsc3ch.o:ricehub.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccWmytNc.o: in function `main':
grader.cpp:(.text.startup+0xae): undefined reference to `besthub(int, int, int*, long long)'
collect2: error: ld returned 1 exit status