QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#793098#9529. Farm ManagementxixuWA 1ms3640kbC++232.5kb2024-11-29 16:41:042024-11-29 16:41:04

Judging History

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

  • [2024-11-29 16:41:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3640kb
  • [2024-11-29 16:41:04]
  • 提交

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});
	}

	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 ++;
	}

	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});
	}

	// 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) {
			// cout << 1;
			summ = (vsu[i].second - w * op);
			// cout << summ << '\n';
			mma = max(su + summ, mma);
		}
		else if(!it) {
			// cout << 2;
			summ = vve[it].first * op - ve[i].first * ve[i].second;
			mma = max(su + summ, mma);
		}
		else {
			// cout << 3;
			summ = vsu[it - 1].second + vve[it].first * (op - vsu[it - 1].first) - ve[i].first * ve[i].second;
			mma = max(su + summ, mma);
		}
		// cout << su + summ << '\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: 1ms
memory: 3640kb

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: 3556kb

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:

39951005

result:

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