Submission #808691

# Submission time Handle Problem Language Result Execution time Memory
808691 2023-08-05T09:33:16 Z vjudge1 코알라 (JOI13_koala) C++17
0 / 100
62 ms 5444 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pill pair<int,ll>
#define mem(a, b) memset(a, b, sizeof(a))
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define name "test"

using namespace std;

const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;

template <typename T1, typename T2> bool maxi(T1 &a, T2 b){if (a < b){a = b; return 1;} return 0;}
template <typename T1, typename T2> bool mini(T1 &a, T2 b){if (a > b){a = b; return 1;} return 0;}

struct SEGTREE{
	ll val[N << 2];
	SEGTREE(){};
	void update(int id, int l, int r, int i, ll x){
		if (l > i || r < i) return;
		if (l == r) return void(val[id] = x);
		int m = (l + r) >> 1;
		if (m >= i) update(id << 1, l, m, i, x);
		else update(id << 1 | 1, m + 1, r, i, x);
		val[id] = max(val[id << 1], val[id << 1 | 1]);
	}

	ll get(int id, int l, int r, int u, int v){
		if (l > v || r < u) return -oo;
		if (l >= u && r <= v) return val[id];
		int m = (l + r) >> 1;
		return max(get(id << 1, l, m, u, v), get(id << 1 | 1, m + 1, r, u, v));
	}
} ST;
int s, t;
int limDis, downPower, n;
int b[N];
pii a[N];

void load(){
	cin.tie(0)->sync_with_stdio(0);
	if (fopen(name".inp", "r")){
		freopen(name".inp", "r", stdin);
		freopen(name".out", "w", stdout);
	}
}

void input(){
	cin >> s >> t >> limDis >> downPower >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i].fi >> a[i].se; 
}

void prepare(){
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; i++)
		b[i] = a[i].fi;
}

void solveUp(){
	prepare();
	int pre_place = s;
	b[0] = s;
	for (int i = 1; i <= n; i++){
		int k = (b[i] - pre_place) / limDis + ((b[i] - pre_place) % limDis > 0);
		ll res = -oo;
		// if (i == 2)
		// 	cout << ST.get(1, 0, n, id, i - 1) << '\n';
		for (int j = k; j <= k + 1; j++){
			int id = lower_bound(b, b + n + 1, b[i] - j * limDis) - b;
			// if (id > 0) id--;
			if (id == 1) id = 0;
			ll tmp = ST.get(1, 0, n, id, i - 1) - downPower * j;
			// if (i == 2)
			// 	cout << j << ' ' << id << ' ' << tmp << '\n';
			maxi(res, tmp + a[i].se);
		}
		// cout << i << ' ' << k << " " << res << '\n';
		ST.update(1, 0, n, i, res);
		pre_place = b[i];
		// if (i == 1)
		// 	for (int j = 0; j <= 1; j++)
		// 		cout << ST.get(1, 0, n, j, j) << ' ';
	}

	int k = (t - pre_place) / limDis + ((t - pre_place) % limDis > 0);
	ll ans = -oo;
	for (int j = k; j <= k + 1; j++){
		int id = lower_bound(b, b + n + 1, t - j * limDis) - b;
		ll tmp = ST.get(1, 0, n, id, n) - j * downPower;
		maxi(ans, tmp);
	}
	cout << ans;
}

int main(){
	load();
	input();
	solveUp();
}

Compilation message

koala.cpp: In function 'void load()':
koala.cpp:49:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |   freopen(name".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
koala.cpp:50:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |   freopen(name".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 54 ms 5444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 5376 KB Output isn't correct
2 Halted 0 ms 0 KB -