QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#678282#9529. Farm Managementucup-team5234#WA 0ms3732kbC++233.5kb2024-10-26 14:32:542024-10-26 14:32:54

Judging History

你现在查看的是最新测评结果

  • [2024-10-26 14:32:54]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3732kb
  • [2024-10-26 14:32:54]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define SZ(x) (int) (x).size()
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(auto i = (a); i < (b); i++)
#define For(i, a, b, c) \
	for(auto i = (a); i != (b); i += (c))
#define REPR(i, n) for(auto i = (n) - 1; i >= 0; i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase(unique(ALL(v)), (v).end())
#define eb emplace_back

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
const double EPS = 1e-6;
const int MOD = 1e9 + 7;
const int INF = (1 << 30);
const ll LINF = 1e18;
const double math_PI = acos(-1);

template<typename T>
vector<T> make_v(size_t a) {
	return vector<T>(a);
}

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(
		a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(
	T &t, const V &v) {
	t = v;
}

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(
	T &t, const V &v) {
	for(auto &e: t) fill_v(e, v);
}

template<class T>
bool chmax(T &a, const T &b) {
	if(a < b) {
		a = b;
		return true;
	}
	return false;
}

template<class T>
bool chmin(T &a, const T &b) {
	if(a > b) {
		a = b;
		return true;
	}
	return false;
}

template<typename S, typename T>
istream &operator>>(istream &is, pair<S, T> &p) {
	cin >> p.first >> p.second;
	return is;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &vec) {
	for(T &x: vec) is >> x;
	return is;
}

template<typename T>
string join(vector<T> &vec, string splitter) {
	stringstream ss;
	REP(i, SZ(vec)) {
		if(i != 0) ss << splitter;
		ss << vec[i];
	}
	return ss.str();
}

template<typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
	os << join(vec, " ");
	return os;
}

#ifdef LOCAL
#include "./cpp-dump/dump.hpp"
#include "./cpp-dump/mytypes.hpp"
#define dump(...) cpp_dump(__VA_ARGS__)
namespace cp = cpp_dump;
#else
#define dump(...)
#define preprocess(...)
#define CPP_DUMP_SET_OPTION(...)
#define CPP_DUMP_DEFINE_EXPORT_OBJECT(...)
#define CPP_DUMP_DEFINE_EXPORT_ENUM(...)
#define CPP_DUMP_DEFINE_DANGEROUS_EXPORT_OBJECT(...)
#endif

int main() {
	int n, m;
	cin >> n >> m;
	ll ans = 0;
	map<ll, ll> M;
	vector<PL> V(n);
	ll mn = 0;
	REP(i, n) {
		ll w, l, r;
		cin >> w >> l >> r;
		V[i] = { w, l };
		ans += w * l;
		mn += l;
		M[w] += r - l;
	}
	ll sum = 0;
	vll A, B, C;
	for(auto [k, v]: M) {
		sum += v;
		A.push_back(k);
		B.push_back(v);
		C.push_back(sum);
	}
	vll D;
	D.push_back(0);
	REPR(i, SZ(C)) {
		D.push_back(D.back() + B[i] * A[i]);
	}
	rev(D);
	dump(A, B, C, D);
	ll mx = 0;
	REP(i, n) {
		auto [w, l] = V[i];
		ll cur = ans - w * l;
		ll rest = m - mn + l;
		auto ind = lower_bound(ALL(A), w) - A.begin();
		if(sum - C[ind] + B[ind] > rest) {
			auto it = lower_bound(C.begin() + ind, C.end(), sum - rest);
			cur += D[(it - C.begin()) + 1] + (*it - (sum - rest)) * A[ind];
			rest = 0;
		} else {
			cur += D[ind];
			rest -= sum - C[ind] + B[ind];
		}
		int k = min(rest, m - B[ind]);
		cur += A[ind] * k;
		rest = 0;
		dump(rest, cur);
		chmax(mx, cur);
	}
	cout << mx << endl;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3732kb

input:

5 17
2 3 4
6 1 5
8 2 4
4 3 3
7 5 5

output:

109

result:

ok single line: '109'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3564kb

input:

12 62
503792 9 10
607358 1 3
600501 10 10
33249 4 4
774438 6 6
197692 3 6
495807 8 8
790225 5 9
77272 3 8
494819 4 9
894779 3 9
306279 5 6

output:

34859047

result:

wrong answer 1st lines differ - expected: '35204500', found: '34859047'