Submission #671558

# Submission time Handle Problem Language Result Execution time Memory
671558 2022-12-13T08:15:54 Z ReLice Divide and conquer (IZhO14_divide) C++14
0 / 100
1 ms 212 KB
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define ld long double
#define pb push_back
#define sz size()
#define fr first
#define sc second
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const ll mod=998244353;
const ll inf=1e18;
const ll N=1e3+10;
void solve(){
    ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
    cin>>n;
    vector <ll> v(n),g(n),e(n),pr(n),pr2(n);
    vector <pair<ll,ll>> v2;
    map<ll,ll> mp;
    for(i=0;i<n;i++){
        cin>>v[i]>>g[i]>>e[i];
        if(i==0) {pr[i]=e[i];pr2[i]=g[i];}
        else {pr[i]=pr[i-1]+e[i]-(v[i]-v[i-1]);pr2[i]=pr2[i-1]+g[i];}
        if(mp[pr[i]]==0 && pr[i]<0) v2.pb({pr[i],i});
        mp[pr[i]]++;
    }
    sort(v2.begin(),v2.end());
    mp.clear();
    for(i=0;i<v2.sz;i++){
        mn=min(mn,v2[i].sc);
        mp[v2[i].fr]=mn;
    }
    for(i=0;i<n;i++){
        if(pr[i]>=0) mx=max(mx,pr2[i]);
        else {
            mx=max(mx,pr2[i]-pr2[mp[pr[i]]]+g[mp[pr[i]]]);
        }
    }
    cout<<mx<<endl;
}
signed main(){
    //fre("divide");
    start();
    ll t=1;
    //cin>>t;
    while(t--) solve();
}

Compilation message

divide.cpp: In function 'void solve()':
divide.cpp:35:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(i=0;i<v2.sz;i++){
      |              ^
divide.cpp:21:10: warning: unused variable 'm' [-Wunused-variable]
   21 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |          ^
divide.cpp:21:12: warning: unused variable 'k' [-Wunused-variable]
   21 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |            ^
divide.cpp:21:16: warning: unused variable 'j' [-Wunused-variable]
   21 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |                ^
divide.cpp:21:18: warning: unused variable 'l' [-Wunused-variable]
   21 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |                  ^
divide.cpp:21:20: warning: unused variable 'r' [-Wunused-variable]
   21 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |                    ^
divide.cpp:21:22: warning: unused variable 'i1' [-Wunused-variable]
   21 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |                      ^~
divide.cpp:21:25: warning: unused variable 'b' [-Wunused-variable]
   21 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |                         ^
divide.cpp:21:27: warning: unused variable 'h' [-Wunused-variable]
   21 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |                           ^
divide.cpp:21:29: warning: unused variable 'w' [-Wunused-variable]
   21 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |                             ^
divide.cpp:21:31: warning: unused variable 'c' [-Wunused-variable]
   21 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |                               ^
divide.cpp:21:35: warning: unused variable 'sum' [-Wunused-variable]
   21 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |                                   ^~~
divide.cpp:21:41: warning: unused variable 'ans' [-Wunused-variable]
   21 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |                                         ^~~
divide.cpp: In function 'void fre(std::string)':
divide.cpp:11:27: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp:11:64: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -