QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#793120#9529. Farm ManagementxixuRE 0ms3640kbC++232.7kb2024-11-29 16:54:152024-11-29 16:54:17

Judging History

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

  • [2024-11-29 16:54:17]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3640kb
  • [2024-11-29 16:54:15]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
#define int long long
// #define int __int128
#define re read()
#define pr(x) print(x)
#define fup(a, b, c, d) for(int a = (b); a <= (c); a += (d))
#define fdo(a, b, c, d) for(int a = (b); a >= (c); a -= (d))
typedef long long ll;
typedef pair<int , int> PII;
typedef map<int , int> MII;
const int inf = 0x3f3f3f3f, N = 2e6 + 10, M = 4e5 + 10, mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;

int n, m;

struct node
{
	int w, l, r, cnt;
};

node op[N];
vector<PII> ve, vve;
vector<PII> vsu;

bool cmp(PII a, PII b)
{
	return a > b;
}

void solve()
{
	cin >> n >> m;

	int su = 0, cnt = 0, mma = 0;

	fup(i, 1, n, 1) {
		int w, l, r;
		cin >> w >> l >> r;
		op[i] = {w, l, r, r - l};
		ve.push_back({w, l});
		su += w * l;
		cnt += l;
		if(r - l) vve.push_back({w, r - l});
	}
	// cout << su << '\n';
	// cout << cnt << '\n';

	sort(ve.begin(), ve.end());
	sort(vve.begin(), vve.end());

	
	mma = su + ve.back().first * (m - cnt);


	int opnu = m - cnt, opsu = 0, f = 0;

	fdo(i, vve.size() - 1, 0, 1) {
		if(opsu + vve[i].second > opnu) {
			vve[i].second -= (opnu - opsu);
			su += (opnu - opsu) * vve[i].first;
			break ;
		}
		opsu += vve[i].second;
		su += vve[i].second * vve[i].first;
		f ++;
	}
	// cout << su << '\n';

	while(f --) {
		vve.pop_back();
	}

	sort(vve.begin(), vve.end(), cmp);

	
	int ssu = 0, cn = 0;

	fup(i, 0, vve.size() - 1, 1) {
		int w = vve[i].first, op = vve[i].second;
		ssu += w * op;
		cn += op;
		vsu.push_back({cn, ssu});
	}
	// cout << su << '\n';

	// for(auto x : ve) {
	// 	cout << x.first << ' ' << x.second << '\n';
	// }
	// cout << '\n';

	// for(auto x : vsu) {
	// 	cout << x.first << ' ' << x.second << '\n';
	// }
	// cout << '\n';

	fup(i, 0, n - 1, 1) {
		int w = ve[i].first, op = ve[i].second, summ;
		// cout << w << ' ' << op << " : ";
		PII x = {op, 0};
		auto it = lower_bound(vsu.begin(), vsu.end(), x) - vsu.begin();
		// cout << it << '\n';
		if(op == vsu[it].first) {
			summ = (vsu[it].second - w * op);
			// cout << w << ' ' << op << ' ' << vsu[i].second << '\n';
			mma = max(su + summ, mma);
		}
		else if(!it) {
			summ = vve[it].first * op - w * op;
			mma = max(su + summ, mma);
		}
		else {
			summ = vsu[it - 1].second + vve[it].first * (op - vsu[it - 1].first) - w * op;
			mma = max(su + summ, mma);
		}
		// cout << su + summ << '\n';
	}
	// cout << '\n';
	cout << mma << '\n';
}

signed main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    int _ = 1;
    // cin >> _;
    while(_ --)
    {
        solve();
    }
}

詳細信息

Test #1:

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

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: 0
Accepted
time: 0ms
memory: 3640kb

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:

35204500

result:

ok single line: '35204500'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

15 32
835418 2 3
178262 1 3
527643 2 2
519710 1 1
774544 3 3
82312 1 1
808199 1 1
809396 1 3
255882 1 3
80467 1 3
874973 1 3
813965 1 2
198275 1 2
152356 1 3
802055 1 1

output:

22000255

result:

ok single line: '22000255'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

13 20
526447 1 1
807398 2 2
4167 1 2
944031 2 2
830685 2 2
394251 1 2
505011 1 2
968848 1 1
58170 1 3
32504 1 1
792273 3 3
196120 1 2
714507 1 1

output:

12878768

result:

ok single line: '12878768'

Test #5:

score: -100
Runtime Error

input:

13 32
582584 1 3
335440 3 3
971984 1 2
864169 1 2
528515 1 1
382399 1 2
459855 1 2
406909 2 3
66780 2 3
885118 3 3
434844 1 2
93331 1 3
502509 1 3

output:


result: