I. Olympiad in Programming and Sports

Codeforces
IDCF730I
Time2000ms
Memory512MB
Difficulty
dpflowsgraphsgreedy
English · Original
Chinese · Translation
Formal · Original
There are _n_ students at Berland State University. Every student has two skills, each measured as a number: _a__i_ — the programming skill and _b__i_ — the sports skill. It is announced that an Olympiad in programming and sports will be held soon. That's why Berland State University should choose two teams: one to take part in the programming track and one to take part in the sports track. There should be exactly _p_ students in the programming team and exactly _s_ students in the sports team. A student can't be a member of both teams. The university management considers that the strength of the university on the Olympiad is equal to the sum of two values: the programming team strength and the sports team strength. The strength of a team is the sum of skills of its members in the corresponding area, so the strength of the programming team is the sum of all _a__i_ and the strength of the sports team is the sum of all _b__i_ over corresponding team members. Help Berland State University to compose two teams to maximize the total strength of the university on the Olympiad. ## Input The first line contains three positive integer numbers _n_, _p_ and _s_ (2 ≤ _n_ ≤ 3000, _p_ + _s_ ≤ _n_) — the number of students, the size of the programming team and the size of the sports team. The second line contains _n_ positive integers _a_1, _a_2, ..., _a__n_ (1 ≤ _a__i_ ≤ 3000), where _a__i_ is the programming skill of the _i_\-th student. The third line contains _n_ positive integers _b_1, _b_2, ..., _b__n_ (1 ≤ _b__i_ ≤ 3000), where _b__i_ is the sports skill of the _i_\-th student. ## Output In the first line, print the the maximum strength of the university on the Olympiad. In the second line, print _p_ numbers — the members of the programming team. In the third line, print _s_ numbers — the members of the sports team. The students are numbered from 1 to _n_ as they are given in the input. All numbers printed in the second and in the third lines should be distinct and can be printed in arbitrary order. If there are multiple solutions, print any of them. [samples]
在贝尔兰国立大学有 #cf_span[n] 名学生。每位学生有两个技能,均以数值衡量:#cf_span[ai] 为编程技能,#cf_span[bi] 为体育技能。 即将举行一场编程与体育奥林匹克竞赛。因此,贝尔兰国立大学需要组建两支队伍:一支参加编程赛道,一支参加体育赛道。 编程队伍必须恰好有 #cf_span[p] 名学生,体育队伍必须恰好有 #cf_span[s] 名学生。一名学生不能同时属于两支队伍。 大学管理层认为,大学在奥林匹克竞赛中的实力等于两个值的和:编程队伍的实力与体育队伍的实力。一支队伍的实力等于其成员在对应领域技能的总和,因此编程队伍的实力是所有 #cf_span[ai] 的和,体育队伍的实力是所有 #cf_span[bi] 的和(分别对应各自队伍的成员)。 请帮助贝尔兰国立大学组建两支队伍,以最大化大学在奥林匹克竞赛中的总实力。 第一行包含三个正整数 #cf_span[n]、#cf_span[p] 和 #cf_span[s](#cf_span[2 ≤ n ≤ 3000],#cf_span[p + s ≤ n])——学生人数、编程队伍规模和体育队伍规模。 第二行包含 #cf_span[n] 个正整数 #cf_span[a1, a2, ..., an](#cf_span[1 ≤ ai ≤ 3000]),其中 #cf_span[ai] 是第 #cf_span[i] 名学生的编程技能。 第三行包含 #cf_span[n] 个正整数 #cf_span[b1, b2, ..., bn](#cf_span[1 ≤ bi ≤ 3000]),其中 #cf_span[bi] 是第 #cf_span[i] 名学生的体育技能。 第一行输出大学在奥林匹克竞赛中的最大实力。第二行输出 #cf_span[p] 个数字——编程队伍的成员。第三行输出 #cf_span[s] 个数字——体育队伍的成员。 学生按输入顺序编号为 1 到 #cf_span[n]。第二行和第三行中输出的所有数字必须互不相同,且可以按任意顺序输出。 如果存在多个解,输出任意一个即可。 ## Input 第一行包含三个正整数 #cf_span[n]、#cf_span[p] 和 #cf_span[s](#cf_span[2 ≤ n ≤ 3000],#cf_span[p + s ≤ n])——学生人数、编程队伍规模和体育队伍规模。第二行包含 #cf_span[n] 个正整数 #cf_span[a1, a2, ..., an](#cf_span[1 ≤ ai ≤ 3000]),其中 #cf_span[ai] 是第 #cf_span[i] 名学生的编程技能。第三行包含 #cf_span[n] 个正整数 #cf_span[b1, b2, ..., bn](#cf_span[1 ≤ bi ≤ 3000]),其中 #cf_span[bi] 是第 #cf_span[i] 名学生的体育技能。 ## Output 第一行输出大学在奥林匹克竞赛中的最大实力。第二行输出 #cf_span[p] 个数字——编程队伍的成员。第三行输出 #cf_span[s] 个数字——体育队伍的成员。学生按输入顺序编号为 1 到 #cf_span[n]。第二行和第三行中输出的所有数字必须互不相同,且可以按任意顺序输出。如果存在多个解,输出任意一个即可。 [samples]
**Definitions** Let $ n, p, s \in \mathbb{Z}^+ $ such that $ 2 \leq n \leq 3000 $ and $ p + s \leq n $. Let $ A = (a_1, a_2, \dots, a_n) $ be the sequence of programming skills. Let $ B = (b_1, b_2, \dots, b_n) $ be the sequence of sports skills. Let $ [n] = \{1, 2, \dots, n\} $ be the set of student indices. **Constraints** 1. Each student belongs to at most one team. 2. The programming team has exactly $ p $ students. 3. The sports team has exactly $ s $ students. 4. The remaining $ n - p - s $ students are unassigned. **Objective** Maximize the total strength: $$ \sum_{i \in P} a_i + \sum_{j \in S} b_j $$ where $ P \subseteq [n] $, $ S \subseteq [n] $, $ |P| = p $, $ |S| = s $, and $ P \cap S = \emptyset $. Output the maximum total strength, followed by any valid sets $ P $ and $ S $.
Samples
Input #1
5 2 2
1 3 4 5 2
5 3 2 1 4
Output #1
18
3 4 
1 5
Input #2
4 2 2
10 8 8 3
10 7 9 4
Output #2
31
1 2 
3 4
Input #3
5 3 1
5 2 5 1 7
6 3 1 6 3
Output #3
23
1 3 5 
4
API Response (JSON)
{
  "problem": {
    "name": "I. Olympiad in Programming and Sports",
    "description": {
      "content": "There are _n_ students at Berland State University. Every student has two skills, each measured as a number: _a__i_ — the programming skill and _b__i_ — the sports skill. It is announced that an Olym",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 524288
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF730I"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There are _n_ students at Berland State University. Every student has two skills, each measured as a number: _a__i_ — the programming skill and _b__i_ — the sports skill.\n\nIt is announced that an Olym...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "在贝尔兰国立大学有 #cf_span[n] 名学生。每位学生有两个技能,均以数值衡量:#cf_span[ai] 为编程技能,#cf_span[bi] 为体育技能。\n\n即将举行一场编程与体育奥林匹克竞赛。因此,贝尔兰国立大学需要组建两支队伍:一支参加编程赛道,一支参加体育赛道。\n\n编程队伍必须恰好有 #cf_span[p] 名学生,体育队伍必须恰好有 #cf_span[s] 名学生。一名学生不能同时...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n, p, s \\in \\mathbb{Z}^+ $ such that $ 2 \\leq n \\leq 3000 $ and $ p + s \\leq n $.  \nLet $ A = (a_1, a_2, \\dots, a_n) $ be the sequence of programming skills.  \nLet $ B = (b_1, ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments