Codeforces Round #557 (Div. 2) A. Zoning Restrictions Again

A. Zoning Restrictions Againtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are planning to build housing on a street. There are nn spots available on the street on which you can build a house. The spots are labeled from 11 to nn from left to right. In each spot, you can build a house with an integer height between 00 and hh.In each spot, if a house has height aa, you will gain a2a2 dollars from it.The city has mm zoning restrictions. The ii-th restriction says that the tallest house from spots lili to riri (inclusive) must be at most xixi.You would like to build houses to maximize your profit. Determine the maximum profit possible.InputThe first line contains three integers nn, hh, and mm (1≤n,h,m≤501≤n,h,m≤50) — the number of spots, the maximum height, and the number of restrictions.Each of the next mm lines contains three integers lili, riri, and xixi (1≤li≤ri≤n1≤li≤ri≤n, 0≤xi≤h0≤xi≤h) — left and right limits (inclusive) of the ii-th restriction and the maximum possible height in that range.OutputPrint a single integer, the maximum profit you can make.
Examplesinput
3 3 3
1 1 1
2 2 3
3 3 2
output
14
input
4 10 2
2 3 8
3 4 7
output
262
NoteIn the first example, there are 33 houses, the maximum height of a house is 33, and there are 33 restrictions. The first restriction says the tallest house between 11 and 11 must be at most 11. The second restriction says the tallest house between 22 and 22 must be at most 33. The third restriction says the tallest house between 33 and 33 must be at most 22.In this case, it is optimal to build houses with heights [1,3,2][1,3,2]. This fits within all the restrictions. The total profit in this case is 12+32+22=1412+32+22=14.In the second example, there are 44 houses, the maximum height of a house is 1010, and there are 22 restrictions. The first restriction says the tallest house from 22 to 33 must be at most 88. The second restriction says the tallest house from 33 to 44 must be at most 77.In this case, it’s optimal to build houses with heights [10,8,7,7][10,8,7,7]. We get a profit of 102+82+72+72=262102+82+72+72=262. Note that there are two restrictions on house 33 and both of them must be satisfied. Also, note that even though there isn’t any explicit restrictions on house 11, we must still limit its height to be at most 1010 (h=10h=10).

大意就是在第二行开始,给定一些要求,前两个数是区间,后一个表示区间内允许的最大值,整合起来取小则是答案

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;

int n, h, m;
int a[55], b[55], c[55];
int ss[55];
long long int ans = 0;
int main() {	
	ios::sync_with_stdio(false);
	cin >> n >> h >> m;
	for (int i = 1; i <= m; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	for (int i = 1; i <= n; i++) {
		ss[i] = h;
	}
	for (int i = 1; i <= m; i++) {
		for (int j = a[i]; j <= b[i]; j++) {
			if (ss[j] >= c[i])ss[j] = c[i];
		}
	}
	for (int i = 1; i <= n; i++) {
		ans += ss[i] * ss[i];
	}
	cout << ans << endl;
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值