# | Submission time^{} |
Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|

157176 | 2019-10-10T01:49:22 Z | combi1k1 | Cake 3 (JOI19_cake3) | C++14 | 4000 ms | 15152 KB |

#pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native" #include<bits/stdc++.h> using namespace std; #define X first #define Y second #define int long long const int N = 2e5 + 1; const int inf = 1e18; typedef pair<int,int> ii; ii T[N]; int n, k; namespace MySet { int L = 1; int R = 0; int Sum = 0; multiset<int> S1; multiset<int> S2; set<int>::iterator it = S1.begin(); void add(int x) { S1.insert(x); S2.insert(x); Sum += x; if (S2.size() > k) { if(*it <= x) ++it; Sum -= *(S2.begin()); S2.erase(S2.begin()); } else it = S1.begin(); } void rem(int x) { if(*it == x) it++; S1.erase(S1.find(x)); if (S2.find(x) == S2.end()) return; S2.erase(S2.find(x)); Sum -= x; x = *(--it); Sum += x; S2.insert(x); } void move(int l,int r) { while (L > l) add(T[--L].Y); while (R < r) add(T[++R].Y); while (L < l) rem(T[L++].Y); while (R > r) rem(T[R--].Y); } }; using MySet::Sum; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for(int i = 1 ; i <= n ; ++i) cin >> T[i].Y >> T[i].X; sort(T + 1,T + 1 + n); queue<ii> q; q.push({k * N + n,N + n - k + 1}); k -= 2; int ans = -1e18; while(q.size()) { int l = q.front().X / N; int r = q.front().X % N; int A = q.front().Y / N; int B = q.front().Y % N; q.pop(); int m = (l + r) / 2; int opt = 0; int cur = -1e18; for(int i = A ; i <= min(B,m - k - 1) ; ++i) { MySet::move(i + 1,m - 1); int nxt = Sum + T[m].Y + T[i].Y - 2 * (T[m].X - T[i].X); if (nxt > cur) { cur = nxt; opt = i; } } ans = max(ans,cur); if (l < m) q.push({l * N + m - 1,A * N + opt}); if (m < r) q.push({m * N + r + N,opt * N + B}); } cout << ans << endl; }

### Compilation message

# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|

1 | Correct | 2 ms | 376 KB | Output is correct |

2 | Correct | 2 ms | 376 KB | Output is correct |

3 | Correct | 2 ms | 508 KB | Output is correct |

4 | Correct | 2 ms | 376 KB | Output is correct |

5 | Correct | 2 ms | 376 KB | Output is correct |

6 | Correct | 2 ms | 376 KB | Output is correct |

7 | Correct | 2 ms | 376 KB | Output is correct |

8 | Correct | 2 ms | 376 KB | Output is correct |

9 | Correct | 2 ms | 380 KB | Output is correct |

10 | Correct | 2 ms | 376 KB | Output is correct |

11 | Correct | 2 ms | 376 KB | Output is correct |

12 | Correct | 2 ms | 376 KB | Output is correct |

13 | Correct | 2 ms | 376 KB | Output is correct |

14 | Correct | 2 ms | 376 KB | Output is correct |

15 | Correct | 2 ms | 376 KB | Output is correct |

16 | Correct | 2 ms | 376 KB | Output is correct |

17 | Correct | 2 ms | 376 KB | Output is correct |

18 | Correct | 2 ms | 376 KB | Output is correct |

19 | Correct | 2 ms | 376 KB | Output is correct |

20 | Correct | 2 ms | 380 KB | Output is correct |

21 | Correct | 2 ms | 376 KB | Output is correct |

22 | Correct | 2 ms | 376 KB | Output is correct |

23 | Correct | 2 ms | 376 KB | Output is correct |

24 | Correct | 3 ms | 376 KB | Output is correct |

25 | Correct | 3 ms | 376 KB | Output is correct |

26 | Correct | 3 ms | 376 KB | Output is correct |

27 | Correct | 3 ms | 376 KB | Output is correct |

28 | Correct | 3 ms | 376 KB | Output is correct |

29 | Correct | 3 ms | 376 KB | Output is correct |

30 | Correct | 3 ms | 376 KB | Output is correct |

31 | Correct | 3 ms | 376 KB | Output is correct |

32 | Correct | 1 ms | 376 KB | Output is correct |

33 | Correct | 3 ms | 376 KB | Output is correct |

34 | Correct | 2 ms | 376 KB | Output is correct |

35 | Correct | 3 ms | 376 KB | Output is correct |

36 | Correct | 2 ms | 376 KB | Output is correct |

37 | Correct | 2 ms | 376 KB | Output is correct |

# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|

1 | Correct | 2 ms | 376 KB | Output is correct |

2 | Correct | 2 ms | 376 KB | Output is correct |

3 | Correct | 2 ms | 508 KB | Output is correct |

4 | Correct | 2 ms | 376 KB | Output is correct |

5 | Correct | 2 ms | 376 KB | Output is correct |

6 | Correct | 2 ms | 376 KB | Output is correct |

7 | Correct | 2 ms | 376 KB | Output is correct |

8 | Correct | 2 ms | 376 KB | Output is correct |

9 | Correct | 2 ms | 380 KB | Output is correct |

10 | Correct | 2 ms | 376 KB | Output is correct |

11 | Correct | 2 ms | 376 KB | Output is correct |

12 | Correct | 2 ms | 376 KB | Output is correct |

13 | Correct | 2 ms | 376 KB | Output is correct |

14 | Correct | 2 ms | 376 KB | Output is correct |

15 | Correct | 2 ms | 376 KB | Output is correct |

16 | Correct | 2 ms | 376 KB | Output is correct |

17 | Correct | 2 ms | 376 KB | Output is correct |

18 | Correct | 2 ms | 376 KB | Output is correct |

19 | Correct | 2 ms | 376 KB | Output is correct |

20 | Correct | 2 ms | 380 KB | Output is correct |

21 | Correct | 2 ms | 376 KB | Output is correct |

22 | Correct | 2 ms | 376 KB | Output is correct |

23 | Correct | 2 ms | 376 KB | Output is correct |

24 | Correct | 3 ms | 376 KB | Output is correct |

25 | Correct | 3 ms | 376 KB | Output is correct |

26 | Correct | 3 ms | 376 KB | Output is correct |

27 | Correct | 3 ms | 376 KB | Output is correct |

28 | Correct | 3 ms | 376 KB | Output is correct |

29 | Correct | 3 ms | 376 KB | Output is correct |

30 | Correct | 3 ms | 376 KB | Output is correct |

31 | Correct | 3 ms | 376 KB | Output is correct |

32 | Correct | 1 ms | 376 KB | Output is correct |

33 | Correct | 3 ms | 376 KB | Output is correct |

34 | Correct | 2 ms | 376 KB | Output is correct |

35 | Correct | 3 ms | 376 KB | Output is correct |

36 | Correct | 2 ms | 376 KB | Output is correct |

37 | Correct | 2 ms | 376 KB | Output is correct |

38 | Correct | 19 ms | 504 KB | Output is correct |

39 | Correct | 21 ms | 504 KB | Output is correct |

40 | Correct | 14 ms | 504 KB | Output is correct |

41 | Correct | 15 ms | 552 KB | Output is correct |

42 | Correct | 9 ms | 504 KB | Output is correct |

43 | Correct | 12 ms | 504 KB | Output is correct |

44 | Correct | 20 ms | 504 KB | Output is correct |

45 | Correct | 20 ms | 504 KB | Output is correct |

46 | Correct | 22 ms | 512 KB | Output is correct |

47 | Correct | 21 ms | 504 KB | Output is correct |

48 | Correct | 20 ms | 504 KB | Output is correct |

49 | Correct | 19 ms | 504 KB | Output is correct |

50 | Correct | 19 ms | 504 KB | Output is correct |

51 | Correct | 18 ms | 504 KB | Output is correct |

52 | Correct | 15 ms | 504 KB | Output is correct |

53 | Correct | 42 ms | 504 KB | Output is correct |

54 | Correct | 12 ms | 504 KB | Output is correct |

55 | Correct | 9 ms | 504 KB | Output is correct |

56 | Correct | 9 ms | 504 KB | Output is correct |

57 | Correct | 11 ms | 504 KB | Output is correct |

58 | Correct | 11 ms | 504 KB | Output is correct |

59 | Correct | 11 ms | 504 KB | Output is correct |

60 | Correct | 13 ms | 504 KB | Output is correct |

61 | Correct | 11 ms | 504 KB | Output is correct |

62 | Correct | 9 ms | 504 KB | Output is correct |

63 | Correct | 10 ms | 476 KB | Output is correct |

64 | Correct | 10 ms | 504 KB | Output is correct |

65 | Correct | 18 ms | 504 KB | Output is correct |

66 | Correct | 17 ms | 504 KB | Output is correct |

67 | Correct | 18 ms | 508 KB | Output is correct |

68 | Correct | 16 ms | 504 KB | Output is correct |

69 | Correct | 15 ms | 504 KB | Output is correct |

70 | Correct | 16 ms | 504 KB | Output is correct |

71 | Correct | 17 ms | 508 KB | Output is correct |

72 | Correct | 11 ms | 504 KB | Output is correct |

73 | Correct | 10 ms | 504 KB | Output is correct |

74 | Correct | 4 ms | 504 KB | Output is correct |

# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|

1 | Correct | 2 ms | 376 KB | Output is correct |

2 | Correct | 2 ms | 376 KB | Output is correct |

3 | Correct | 2 ms | 508 KB | Output is correct |

4 | Correct | 2 ms | 376 KB | Output is correct |

5 | Correct | 2 ms | 376 KB | Output is correct |

6 | Correct | 2 ms | 376 KB | Output is correct |

7 | Correct | 2 ms | 376 KB | Output is correct |

8 | Correct | 2 ms | 376 KB | Output is correct |

9 | Correct | 2 ms | 380 KB | Output is correct |

10 | Correct | 2 ms | 376 KB | Output is correct |

11 | Correct | 2 ms | 376 KB | Output is correct |

12 | Correct | 2 ms | 376 KB | Output is correct |

13 | Correct | 2 ms | 376 KB | Output is correct |

14 | Correct | 2 ms | 376 KB | Output is correct |

15 | Correct | 2 ms | 376 KB | Output is correct |

16 | Correct | 2 ms | 376 KB | Output is correct |

17 | Correct | 2 ms | 376 KB | Output is correct |

18 | Correct | 2 ms | 376 KB | Output is correct |

19 | Correct | 2 ms | 376 KB | Output is correct |

20 | Correct | 2 ms | 380 KB | Output is correct |

21 | Correct | 2 ms | 376 KB | Output is correct |

22 | Correct | 2 ms | 376 KB | Output is correct |

23 | Correct | 2 ms | 376 KB | Output is correct |

24 | Correct | 3 ms | 376 KB | Output is correct |

25 | Correct | 3 ms | 376 KB | Output is correct |

26 | Correct | 3 ms | 376 KB | Output is correct |

27 | Correct | 3 ms | 376 KB | Output is correct |

28 | Correct | 3 ms | 376 KB | Output is correct |

29 | Correct | 3 ms | 376 KB | Output is correct |

30 | Correct | 3 ms | 376 KB | Output is correct |

31 | Correct | 3 ms | 376 KB | Output is correct |

32 | Correct | 1 ms | 376 KB | Output is correct |

33 | Correct | 3 ms | 376 KB | Output is correct |

34 | Correct | 2 ms | 376 KB | Output is correct |

35 | Correct | 3 ms | 376 KB | Output is correct |

36 | Correct | 2 ms | 376 KB | Output is correct |

37 | Correct | 2 ms | 376 KB | Output is correct |

38 | Correct | 19 ms | 504 KB | Output is correct |

39 | Correct | 21 ms | 504 KB | Output is correct |

40 | Correct | 14 ms | 504 KB | Output is correct |

41 | Correct | 15 ms | 552 KB | Output is correct |

42 | Correct | 9 ms | 504 KB | Output is correct |

43 | Correct | 12 ms | 504 KB | Output is correct |

44 | Correct | 20 ms | 504 KB | Output is correct |

45 | Correct | 20 ms | 504 KB | Output is correct |

46 | Correct | 22 ms | 512 KB | Output is correct |

47 | Correct | 21 ms | 504 KB | Output is correct |

48 | Correct | 20 ms | 504 KB | Output is correct |

49 | Correct | 19 ms | 504 KB | Output is correct |

50 | Correct | 19 ms | 504 KB | Output is correct |

51 | Correct | 18 ms | 504 KB | Output is correct |

52 | Correct | 15 ms | 504 KB | Output is correct |

53 | Correct | 42 ms | 504 KB | Output is correct |

54 | Correct | 12 ms | 504 KB | Output is correct |

55 | Correct | 9 ms | 504 KB | Output is correct |

56 | Correct | 9 ms | 504 KB | Output is correct |

57 | Correct | 11 ms | 504 KB | Output is correct |

58 | Correct | 11 ms | 504 KB | Output is correct |

59 | Correct | 11 ms | 504 KB | Output is correct |

60 | Correct | 13 ms | 504 KB | Output is correct |

61 | Correct | 11 ms | 504 KB | Output is correct |

62 | Correct | 9 ms | 504 KB | Output is correct |

63 | Correct | 10 ms | 476 KB | Output is correct |

64 | Correct | 10 ms | 504 KB | Output is correct |

65 | Correct | 18 ms | 504 KB | Output is correct |

66 | Correct | 17 ms | 504 KB | Output is correct |

67 | Correct | 18 ms | 508 KB | Output is correct |

68 | Correct | 16 ms | 504 KB | Output is correct |

69 | Correct | 15 ms | 504 KB | Output is correct |

70 | Correct | 16 ms | 504 KB | Output is correct |

71 | Correct | 17 ms | 508 KB | Output is correct |

72 | Correct | 11 ms | 504 KB | Output is correct |

73 | Correct | 10 ms | 504 KB | Output is correct |

74 | Correct | 4 ms | 504 KB | Output is correct |

75 | Execution timed out | 4059 ms | 15152 KB | Time limit exceeded |

76 | Halted | 0 ms | 0 KB | - |