tinycodinglm / cp2 /cp-0042.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 15)
b27bfb3 verified
|
Raw History Blame Contribute Delete
9.15 kB
cp-practice-sim trace
System You are a competitive-programming assistant. Deliver correct, complete, runnable solutions that read standard input and write standard output. Reply with code only; no explanation. Tools: write_file(path, content) writes...

You are a competitive-programming assistant. Deliver correct, complete, runnable solutions that read standard input and write standard output. Reply with code only; no explanation. Tools: write_file(path, content) writes a UTF-8 file (creating directories); run_shell(command) runs a bash command and returns its output and exit status. Test solutions on the provided examples before answering.

User 2026-11-08T15:20:03.537Z

Sled Pairs

Topic: Sorting and greedy | Difficulty: easy

Problem

n children (n even) with given weights must be split into n/2 pairs, each pair sharing one sled. A pair's load is the sum of its two weights. Print the smallest possible value of the largest load over all pairs.

Input

The first line contains n. The second line contains the n weights.

Output

Print one integer: the minimum possible maximum pair load.

Constraints

  • 2 <= n <= 2*10^5, n is even
  • 1 <= weight <= 10^9

Examples

Example 1

Input:

markdown
4
3 1 4 2

Output:

markdown
5

Note: Pairs (1,4) and (2,3) both have load 5.

Example 2

Input:

markdown
2
7 7

Output:

markdown
14

Solve this task. Write solutions in Java 17, Go, Ruby, test what you can run on the examples, and send back the final programs. Final answer: code only, no explanation.

Assistant 2026-11-08T15:20:05.511Z

Writing the Java 17 solution and testing it on the examples.

Assistant 2026-11-08T15:20:09.870Z

Saving the example inputs.

2 tool calls (write_file)
Assistant 2026-11-08T15:20:16.536Z

Compiling the Java 17 solution.

Assistant 2026-11-08T15:20:20.465Z

Running every example.

2 tool calls (run_shell)
Assistant 2026-11-08T15:20:27.386Z

Cross-checking with the Go version.

Assistant 2026-11-08T15:20:31.785Z

Compiling the Go solution.

Assistant 2026-11-08T15:20:35.832Z

Running every example.

2 tool calls (run_shell)
Assistant 2026-11-08T15:20:42.930Z

Cross-checking with the Ruby version.

Assistant 2026-11-08T15:20:46.547Z

Running every example.

2 tool calls (run_shell)
Assistant 2026-11-08T15:20:53.000Z

All solutions below passed every example.

Java 17

java
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine().trim());
        StringTokenizer st = new StringTokenizer(br.readLine());
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = Long.parseLong(st.nextToken());
        Arrays.sort(a);
        long best = 0;
        for (int i = 0; i < n / 2; i++) best = Math.max(best, a[i] + a[n - 1 - i]);
        System.out.println(best);
    }
}

Go

go
package main

import (
    "bufio"
    "fmt"
    "os"
    "sort"
)

func main() {
    rd := bufio.NewReader(os.Stdin)
    var n int
    fmt.Fscan(rd, &n)
    a := make([]int, n)
    for i := range a {
        fmt.Fscan(rd, &a[i])
    }
    sort.Ints(a)
    best := 0
    for i := 0; i < n/2; i++ {
        if s := a[i] + a[n-1-i]; s > best {
            best = s
        }
    }
    fmt.Println(best)
}

Ruby

ruby
n = gets.to_i
a = gets.split.map(&:to_i).sort
best = 0
(n / 2).times do |i|
  s = a[i] + a[n - 1 - i]
  best = s if s > best
end
puts best