编程介的小学生 2019-12-31 09:31 采纳率: 0.2%
浏览 77

Dual Processing Task 正确写法是什么

Problem Description
N items are to be processed with two product lines. YY operates the first line, and LMY operates the second. YY can use X processing modes for the first product
line, with his ith mode, processing an item costs Ai units of material while the item’s value increases by Pi units. Similarly LMY can use Y modes for the second
product line, with her ith mode processing an item will cost Bi units of material and get Qi units of value increment. All items must be processed in both of the
product lines, each with one of their modes, to satisfy both YY and LMY. Note that when processing an item with some mode of a product line, the cost and value
increment are totally irrelevant to the mode chosen in the other line. YY and LMY want the value increment of the items to be maximized, but there are only M
units of material available. So they have to choose their modes carefully, use no more than M units of material and still make the value increment as large as possible.

Input
The input file contains several test cases.

The first line of each test case contains two integers N and M indicating the number of items to be processed and the quantity of material available. The next line
contains an integer X, the number of modes YY has. X lines follow, the ith line of which contains two integers Ai and Pi, the material utilized and the value
increased by YY’s ith mode of the first product line. The next line contains an integer Y, the number of modes LMY has. Y lines follow, the ith line of which contains
two integers Bi and Qi, the material utilized and the value increased by LMY’s ith mode of the second product line.

All integers except N are less than or equal to 800 and non-negative, while X and Y are always positive. N is a non-negetive integer no more than 100000.
A line with N=M=0 indicates the end of input, and should not be processed.

Output
For each test case, output one line containing an integer, the maximum value increment after YY and LMY have processed all the N items with no more than M
units of material cost.

Sample Input
3 100
1
1 1
1
2 2
0 0

Sample Output
9

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-07-27 11:48
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    # read data
    N <- readLines()[[1]][[1]]
    M <- readLines()[[1]][[2]]
    X <- as.integer(readLines()[[1]][[3]])
    Y <- as.integer(readLines()[[1]][[4]])
    
    A <- matrix(NA, nrow=X, ncol=N)
    B <- matrix(NA, nrow=Y, ncol=N)
    
    for (i in 1:N) {
        A[i,] <- readLines()[[i]][[1]]
    }
    
    for (j in 1:X) {
        B[j,] <- readLines()[[j]][[1]]
    }
    
    max_vinc <- 0
    for (k in 1:M) {
        vinc <- sum(A[k,]) + sum(B[k,])
        if (vinc <= M) {
            max_vinc <- max(max_vinc, vinc * (sum(A[k,]) + sum(B[k,])))
        }
    }
    print(max_vinc)
    
    评论

报告相同问题?

悬赏问题

  • ¥200 csgo2的viewmatrix值是否还有别的获取方式
  • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
  • ¥15 请把下列每一行代码完整地读懂并注释出来
  • ¥15 pycharm运行main文件,显示没有conda环境
  • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件
  • ¥15 为什么eclipse不能再下载了?
  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题
  • ¥50 如何将脑的图像投影到颅骨上