Submission #1350486

#TimeUsernameProblemLanguageResultExecution timeMemory
1350486icebearFuel Station (NOI20_fuelstation)C++20
Compilation error
0 ms0 KiB
/* AUTHOR: TUAN ANH - BUI */
// ~~ icebear ~~
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

template<class X, class Y>
    bool minimize(X &x, const Y &y) {
        if (x > y) return x = y, true;
        return false;
    }

template<class X, class Y>
    bool maximize(X &x, const Y &y) {
        if (x < y) return x = y, true;
        return false;
    }

#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define MASK(i) (1LL << (i))
#define BIT(S, i) (((S) >> (i)) & 1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebear"
/*END OF TEMPLATE. I love my cats <3 */

const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 27092008;
const ll INF  = (ll)1e18 + 27092008;
const int N = 3e5 + 5;
int n, H;
struct Station {
    int x, f, r;
    bool operator < (const Station &other) const {
        return x < other.x;
    }
} S[N];

void init(void) {
    cin >> n >> H;
    FOR(i, 1, n) cin >> S[i].x >> S[i].f >> S[i].r;
    sort(S + 1, S + n + 1);
}

void process(void) {
    auto check = [&](long long V) {
        int init = V;
        FOR(i, 1, n) if (V >= S[i].x && init <= S[i].r) V += S[i].f;
        return V >= H;
    };

    if (check(S[1].x)) return void(cout << S[1].x;)
    int low = 0, high = 0, res = -1;
    FOR(i, 1, n) maximize(high, S[i].r);
    while(low <= high) {
        int mid = (low + high) >> 1;
        if (check(mid)) res = mid, high = mid - 1;
        else low = mid + 1;
    }
    cout << (res == -1 ? H : res);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if (fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int tc = 1;
//    cin >> tc;
    while(tc--) {
        init();
        process();
    }
    return 0;
}

Compilation message (stderr)

FuelStation.cpp: In function 'void process()':
FuelStation.cpp:61:31: error: expected primary-expression before 'void'
   61 |     if (check(S[1].x)) return void(cout << S[1].x;)
      |                               ^~~~
FuelStation.cpp:61:30: error: expected ';' before 'void'
   61 |     if (check(S[1].x)) return void(cout << S[1].x;)
      |                              ^~~~~
      |                              ;
FuelStation.cpp:61:31: error: expected primary-expression before 'void'
   61 |     if (check(S[1].x)) return void(cout << S[1].x;)
      |                               ^~~~
FuelStation.cpp:61:51: error: expected primary-expression before ')' token
   61 |     if (check(S[1].x)) return void(cout << S[1].x;)
      |                                                   ^
FuelStation.cpp:63:27: error: 'high' was not declared in this scope
   63 |     FOR(i, 1, n) maximize(high, S[i].r);
      |                           ^~~~
FuelStation.cpp:64:11: error: 'low' was not declared in this scope; did you mean 'pow'?
   64 |     while(low <= high) {
      |           ^~~
      |           pow
FuelStation.cpp:64:18: error: 'high' was not declared in this scope
   64 |     while(low <= high) {
      |                  ^~~~
FuelStation.cpp:66:25: error: 'res' was not declared in this scope
   66 |         if (check(mid)) res = mid, high = mid - 1;
      |                         ^~~
FuelStation.cpp:69:14: error: 'res' was not declared in this scope
   69 |     cout << (res == -1 ? H : res);
      |              ^~~
FuelStation.cpp: In function 'int main()':
FuelStation.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
FuelStation.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~