| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 | 
							- package main
 
- import (
 
- 	"bufio"
 
- 	"fmt"
 
- 	"os"
 
- 	"sort"
 
- )
 
- func minProduct(scanner *bufio.Scanner) []int64 {
 
- 	caseCnt := ReadInt(scanner) // Math AGAIN.
 
- 	answer := make([]int64, caseCnt)
 
- 	for i := 0; i < caseCnt; i++ {
 
- 		// n = 2 is a very impotant case, because:
 
- 		// if x < x', y < y', then xy'+x'y - xy - x'y'
 
- 		// = -(x' - x)(y' - y) < 0, so xy'+x'y < xy + x'y'
 
- 		vecDim := ReadInt(scanner)
 
- 		vec1 := ReadInts(scanner)
 
- 		vec2 := ReadInts(scanner)
 
- 		sort.Ints(vec1)
 
- 		sort.Ints(vec2)
 
- 		for j := 0; j < vecDim; j++ {
 
- 			answer[i] += int64(vec1[j] * vec2[vecDim-1-j])
 
- 		}
 
- 	}
 
- 	return answer
 
- }
 
- func main() {
 
- 	inputFiles := []string{"A-small-practice.in", "A-large-practice.in", "test.in"}
 
- 	outputFiles := []string{"result-small.out", "result-large.out", "test.out"}
 
- 	const (
 
- 		small = iota
 
- 		large
 
- 		test
 
- 	)
 
- 	fileType := large
 
- 	fin, _ := os.Open(inputFiles[fileType])
 
- 	defer fin.Close()
 
- 	scanner := bufio.NewScanner(fin)
 
- 	answer := minProduct(scanner)
 
- 	fout, _ := os.Create(outputFiles[fileType])
 
- 	defer fout.Close()
 
- 	for i, n := range answer {
 
- 		s := fmt.Sprintf("Case #%d: %d\n", i+1, n)
 
- 		fout.WriteString(s)
 
- 	}
 
- }
 
 
  |