#K81317. Minimum Weight Sum Excluding the Lightest

    ID: 35727 Type: Default 1000ms 256MiB

Minimum Weight Sum Excluding the Lightest

Minimum Weight Sum Excluding the Lightest

You are given a sequence of weights representing different items and several sets that reference these items by their indices. For each set, your task is to compute the sum of weights after excluding the lightest item in that set. In other words, for each set, remove the element with the minimum weight and output the summation of the remaining weights.

This problem requires careful input parsing and proper aggregation of data while handling basic array operations.

inputFormat

The input is read from stdin and has the following format:

  • The first line contains an integer \(n\), the number of weights.
  • The second line contains \(n\) space-separated integers representing the weights.
  • The third line contains an integer \(m\), the number of sets.
  • Each of the next \(m\) lines starts with an integer \(k\) (the number of indices in the set), followed by \(k\) space-separated integers representing the 1-indexed positions of the weights in that set.

outputFormat

The output should be written to stdout as a single line containing \(m\) space-separated integers. Each integer is the computed total weight sum for the corresponding set after excluding its minimum weight.

## sample
6
4 2 3 5 6 1
3
3 1 2 3
2 4 5
4 1 3 5 6
7 6 13