답안 #384669

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384669 2021-04-02T04:06:09 Z zoooma13 금 캐기 (IZhO14_divide) C++14
100 / 100
72 ms 10820 KB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    vector <array<int64_t ,3>> a(n);
    for(auto&x : a)
        scanf("%lld%lld%lld",&x[0],&x[1],&x[2]);
    a.insert(a.begin() ,{0,0,0});
    set <pair<int64_t ,int64_t>> ss;
    int64_t ans = 0;
    for(int i=1; i<=n; i++){
        ans = max(ans ,a[i][1]);
        a[i][1] += a[i-1][1];
        a[i][2] += a[i-1][2];

        auto it = ss.upper_bound({a[i][2] - a[i][0] ,0});
        if(it != ss.begin()){
            it = prev(it);
            ans = max(ans ,a[i][1] - it->second);
        }

        it = ss.insert({a[i-1][2] - a[i][0] ,a[i-1][1]}).first;
        if(it == ss.begin() || prev(it)->second > it->second){
            while(next(it) != ss.end() && next(it)->second >= it->second)
                ss.erase(next(it));
        }else{
            ss.erase(it);
        }
        ///a[i][2]-a[j][2] - (a[i][0]-a[j][0]) >= 0
        ///a[i][2] - a[i][0] >= a[j][2] - a[j][0]
    }
    printf("%lld\n",ans);
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:10:19: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'std::array<long int, 3>::value_type*' {aka 'long int*'} [-Wformat=]
   10 |         scanf("%lld%lld%lld",&x[0],&x[1],&x[2]);
      |                ~~~^
      |                   |
      |                   long long int*
      |                %ld
divide.cpp:10:23: warning: format '%lld' expects argument of type 'long long int*', but argument 3 has type 'std::array<long int, 3>::value_type*' {aka 'long int*'} [-Wformat=]
   10 |         scanf("%lld%lld%lld",&x[0],&x[1],&x[2]);
      |                    ~~~^
      |                       |
      |                       long long int*
      |                    %ld
divide.cpp:10:27: warning: format '%lld' expects argument of type 'long long int*', but argument 4 has type 'std::array<long int, 3>::value_type*' {aka 'long int*'} [-Wformat=]
   10 |         scanf("%lld%lld%lld",&x[0],&x[1],&x[2]);
      |                        ~~~^
      |                           |
      |                           long long int*
      |                        %ld
divide.cpp:35:16: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'int64_t' {aka 'long int'} [-Wformat=]
   35 |     printf("%lld\n",ans);
      |             ~~~^    ~~~
      |                |    |
      |                |    int64_t {aka long int}
      |                long long int
      |             %ld
divide.cpp:7:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    7 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
divide.cpp:10:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |         scanf("%lld%lld%lld",&x[0],&x[1],&x[2]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 4 ms 748 KB Output is correct
24 Correct 4 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 4 ms 748 KB Output is correct
24 Correct 4 ms 748 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 4 ms 748 KB Output is correct
27 Correct 5 ms 748 KB Output is correct
28 Correct 19 ms 2668 KB Output is correct
29 Correct 24 ms 3948 KB Output is correct
30 Correct 41 ms 6764 KB Output is correct
31 Correct 37 ms 6764 KB Output is correct
32 Correct 37 ms 6764 KB Output is correct
33 Correct 36 ms 6636 KB Output is correct
34 Correct 61 ms 7364 KB Output is correct
35 Correct 72 ms 10820 KB Output is correct
36 Correct 69 ms 10436 KB Output is correct