-
Notifications
You must be signed in to change notification settings - Fork 577
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df2c740
commit 58e5d0f
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
. "fmt" | ||
"io" | ||
"sort" | ||
) | ||
|
||
// github.com/EndlessCheng/codeforces-go | ||
func CF777E(_r io.Reader, out io.Writer) { | ||
in := bufio.NewReader(_r) | ||
var n int | ||
Fscan(in, &n) | ||
a := make([]struct{ r, R, h int }, n) | ||
for i := range a { | ||
Fscan(in, &a[i].r, &a[i].R, &a[i].h) | ||
} | ||
sort.Slice(a, func(i, j int) bool { a, b := a[i], a[j]; return a.R > b.R || a.R == b.R && a.r > b.r }) | ||
|
||
sum := int64(a[0].h) | ||
ans := sum | ||
s := []int{0} | ||
for i := 1; i < n; i++ { | ||
for len(s) > 0 && a[s[len(s)-1]].r >= a[i].R { | ||
sum -= int64(a[s[len(s)-1]].h) | ||
s = s[:len(s)-1] | ||
} | ||
s = append(s, i) | ||
sum += int64(a[i].h) | ||
if sum > ans { | ||
ans = sum | ||
} | ||
} | ||
Fprint(out, ans) | ||
} | ||
|
||
//func main() { CF777E(os.Stdin, os.Stdout) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/EndlessCheng/codeforces-go/main/testutil" | ||
"testing" | ||
) | ||
|
||
// https://codeforces.com/problemset/problem/777/E | ||
// https://codeforces.com/problemset/status/777/problem/E | ||
func TestCF777E(t *testing.T) { | ||
// just copy from website | ||
rawText := ` | ||
inputCopy | ||
3 | ||
1 5 1 | ||
2 6 2 | ||
3 7 3 | ||
outputCopy | ||
6 | ||
inputCopy | ||
4 | ||
1 2 1 | ||
1 3 3 | ||
4 6 2 | ||
5 7 1 | ||
outputCopy | ||
4` | ||
testutil.AssertEqualCase(t, rawText, 0, CF777E) | ||
} |