Submission #1662353
Source Code Expand
package main import ( "bufio" "fmt" "os" "sort" "strconv" ) func main() { scn := newScanner() W := scn.nextInt() H := scn.nextInt() p := make([]int, W) q := make([]int, H) for i := 0; i < W; i++ { p[i] = scn.nextInt() } for i := 0; i < H; i++ { q[i] = scn.nextInt() } sort.Ints(p) sort.Ints(q) var i, j, ans int for i < H || j < W { if i == H { ans += p[j] j++ } else if j == W { ans += q[i] i++ } else { if q[i] < p[j] { ans += (W - j + 1) * q[i] i++ } else { ans += (H - i + 1) * p[j] j++ } } } fmt.Println(ans) } func max(a ...int) int { r := a[0] for i := 0; i < len(a); i++ { if r < a[i] { r = a[i] } } return r } func min(a ...int) int { r := a[0] for i := 0; i < len(a); i++ { if r > a[i] { r = a[i] } } return r } type scanner struct { r *bufio.Reader buf []byte p int } func newScanner() *scanner { rdr := bufio.NewReaderSize(os.Stdin, 10000) return &scanner{r: rdr} } func (s *scanner) next() string { s.pre() start := s.p for ; s.p < len(s.buf); s.p++ { if s.buf[s.p] == ' ' { break } } result := string(s.buf[start:s.p]) s.p++ return result } func (s *scanner) nextLine() string { s.pre() start := s.p s.p = len(s.buf) return string(s.buf[start:]) } func (s *scanner) nextInt() int { v, _ := strconv.Atoi(s.next()) return v } func (s *scanner) nextInt64() int64 { v, _ := strconv.ParseInt(s.next(), 10, 64) return v } func (s *scanner) pre() { if s.p >= len(s.buf) { s.readLine() s.p = 0 } } func (s *scanner) readLine() { s.buf = make([]byte, 0) for { l, p, e := s.r.ReadLine() if e != nil { panic(e) } s.buf = append(s.buf, l...) if !p { break } } }
Submission Info
Submission Time | |
---|---|
Task | C - Gr-idian MST |
User | fmhr |
Language | Go (1.6) |
Score | 500 |
Code Size | 1839 Byte |
Status | AC |
Exec Time | 114 ms |
Memory | 5504 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, s1.txt, s2.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 108 ms | 4608 KB |
02.txt | AC | 108 ms | 4608 KB |
03.txt | AC | 114 ms | 5248 KB |
04.txt | AC | 107 ms | 4608 KB |
05.txt | AC | 108 ms | 4608 KB |
06.txt | AC | 106 ms | 4608 KB |
07.txt | AC | 107 ms | 4608 KB |
08.txt | AC | 107 ms | 4608 KB |
09.txt | AC | 106 ms | 4608 KB |
10.txt | AC | 107 ms | 4608 KB |
11.txt | AC | 102 ms | 5248 KB |
12.txt | AC | 95 ms | 4608 KB |
13.txt | AC | 82 ms | 4608 KB |
14.txt | AC | 107 ms | 4608 KB |
15.txt | AC | 113 ms | 5248 KB |
16.txt | AC | 52 ms | 3072 KB |
17.txt | AC | 52 ms | 3072 KB |
18.txt | AC | 53 ms | 3072 KB |
19.txt | AC | 53 ms | 3072 KB |
20.txt | AC | 60 ms | 5248 KB |
21.txt | AC | 79 ms | 4608 KB |
22.txt | AC | 77 ms | 4608 KB |
23.txt | AC | 76 ms | 4608 KB |
24.txt | AC | 73 ms | 5504 KB |
25.txt | AC | 1 ms | 640 KB |
26.txt | AC | 1 ms | 640 KB |
27.txt | AC | 1 ms | 640 KB |
28.txt | AC | 1 ms | 640 KB |
s1.txt | AC | 1 ms | 640 KB |
s2.txt | AC | 1 ms | 640 KB |