3165. Maximum Sum of Subsequence With Non-adjacent Elements
You are given an array
nums
consisting of integers. You are also given a 2D arrayqueries
, wherequeries[i] = [posi, xi]
.For query
i
, we first setnums[posi]
equal toxi
, then we calculate the answer to queryi
which is the maximum sum of a subsequence ofnums
where no two adjacent elements are selected.Return the sum of the answers to all queries.
Since the final answer may be very large, return it modulo
109 + 7
.A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.
c++
1 |
|