NC221647. What'sMineisMine
描述
输入描述
Your program is to read from standard input. The input starts with a line containing two integers, ݉m and n (1 ≤ m ≤100, 1 ≤n ≤ 10,000), where ݉m is the number of types of minerals and n is the number of ore occurrences during the day. The mineral types are labeled from 1 to ݉m. The following ݉m lines contain a single integer corresponding to the price of one unit of the i-th mineral type on that day (the price is between 1 and 10,000). The following n lines represent ore occurrences. Each line contains three integers, s, e݁, t where s is the start time, e is the end time and t is the mineral type in each ore occurrence with 0 < s < e < 15,000 and 1 ≤ t ≤ m. The amount of mineral at each occurrence is ݁e - s.
输出描述
Your program is to write to standard output. Print exactly one line. The line should contain the maximum amount of money that can be earned on that day.
The following shows sample input and output for three test cases.
示例1
输入:
2 5 2 3 2 5 1 4 5 2 4 6 1 7 11 2 6 10 1
输出:
18
示例2
输入:
3 5 2 3 1 1 4 1 3 6 3 5 8 2 7 10 1 9 12 2
输出:
24
示例3
输入:
5 7 1 2 3 4 5 1 5 2 3 8 1 2 4 3 3 9 2 4 10 5 7 11 4 5 7 3
输出:
36
Python3(3.9) 解法, 执行用时: 55ms, 内存消耗: 4772K, 提交时间: 2021-05-05 14:42:12
m,n=map(int,input().split()) p=[0] for i in range(m): p.append(int(input())) mi=[] for i in range(n): mi.append([int(x) for x in input().split()]) mine=sorted(mi,key=lambda x:x[1]) l=len(mine) dp=[0]*(mine[l-1][1]+1) c=0 for i in range(1,mine[l-1][1]+1): for j in range(c,l): if mine[j][1]<=i: dp[i]=max(dp[mine[j][0]]+(mine[j][1]-mine[j][0])*p[mine[j][2]],dp[i]) else: c=j break dp[i]=max(dp[i-1],dp[i]) print(dp[mine[l-1][1]])
C++(clang++11) 解法, 执行用时: 227ms, 内存消耗: 32504K, 提交时间: 2021-05-05 14:25:49
#include<bits/stdc++.h> using namespace std; int brr[10005]; int arr[10005][10005]; int maxx=-10; int main() { int n,m; cin>>n>>m; for(int i=1;i<=n;i++) cin>>brr[i]; for(int i=1;i<=m;i++) { int a,b,c; cin>>a>>b>>c; arr[a][b]=abs(a-b)*brr[c]; maxx=max(maxx,b); } for(int i=1;i<=maxx;i++) { for(int j=1;j<=i;j++) { arr[1][i]=max(arr[1][i],arr[1][j]+arr[j][i]); } } printf("%d\n",arr[1][maxx]); }