Submission #167753

# Submission time Handle Problem Language Result Execution time Memory
167753 2019-12-10T03:40:35 Z daniyar03 Divide and conquer (IZhO14_divide) C++14
17 / 100
64 ms 7160 KB
#include<bits/stdc++.h>
#define int long long int
using namespace std;
struct data{
    int x,g,d;
};
bool cmp(data l,data r){
    return l.x<r.x||l.x==r.x&&l.d>r.d||l.x==r.x&&l.d==r.d&&l.g>r.g;
}
data a[100001];
int n,i,l,r,gold[100001],drive[100001],mx,m;
main(){
    scanf("%lld",&n);
    for(i=1;i<=n;i++)scanf("%lld%lld%lld",&a[i].x,&a[i].g,&a[i].d);
    sort(a+1,a+1+n,cmp);
    for(i=1;i<=n;i++)gold[i]=gold[i-1]+a[i].g,drive[i]=drive[i-1]+a[i].d;
    for(i=1;i<=n;i++){
        l=i;
        r=n;
        while(l<r){
            m=(l+r+1)>>1;
            if(drive[m]-drive[i-1]>=a[m].x-a[i].x)l=m;
            else r=m-1;
        }
        mx=max(mx,gold[l]-gold[i-1]);
    }
    cout<<mx;
}

Compilation message

divide.cpp: In function 'bool cmp(data, data)':
divide.cpp:8:29: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
     return l.x<r.x||l.x==r.x&&l.d>r.d||l.x==r.x&&l.d==r.d&&l.g>r.g;
                     ~~~~~~~~^~~~~~~~~
divide.cpp:8:58: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
     return l.x<r.x||l.x==r.x&&l.d>r.d||l.x==r.x&&l.d==r.d&&l.g>r.g;
                                        ~~~~~~~~~~~~~~~~~~^~~~~~~~~
divide.cpp: At global scope:
divide.cpp:12:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
divide.cpp: In function 'int main()':
divide.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&n);
     ~~~~~^~~~~~~~~~~
divide.cpp:14:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1;i<=n;i++)scanf("%lld%lld%lld",&a[i].x,&a[i].g,&a[i].d);
                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 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 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 252 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 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 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 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 6 ms 760 KB Output is correct
3 Correct 7 ms 760 KB Output is correct
4 Correct 26 ms 2300 KB Output is correct
5 Correct 31 ms 3576 KB Output is correct
6 Correct 64 ms 7160 KB Output is correct
7 Correct 49 ms 5980 KB Output is correct
8 Correct 50 ms 6136 KB Output is correct
9 Correct 48 ms 5880 KB Output is correct
10 Incorrect 49 ms 5880 KB Output isn't correct
11 Halted 0 ms 0 KB -