Submission #671590

# Submission time Handle Problem Language Result Execution time Memory
671590 2022-12-13T09:05:04 Z ReLice Divide and conquer (IZhO14_divide) C++14
0 / 100
2 ms 4180 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=1e5+10;
vector <ll> v(N),g(N),e(N),pr(N),pr2(N);
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 <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:22:10: warning: unused variable 'm' [-Wunused-variable]
   22 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |          ^
divide.cpp:22:12: warning: unused variable 'k' [-Wunused-variable]
   22 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |            ^
divide.cpp:22:16: warning: unused variable 'j' [-Wunused-variable]
   22 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |                ^
divide.cpp:22:18: warning: unused variable 'l' [-Wunused-variable]
   22 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |                  ^
divide.cpp:22:20: warning: unused variable 'r' [-Wunused-variable]
   22 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |                    ^
divide.cpp:22:22: warning: unused variable 'i1' [-Wunused-variable]
   22 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |                      ^~
divide.cpp:22:25: warning: unused variable 'b' [-Wunused-variable]
   22 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |                         ^
divide.cpp:22:27: warning: unused variable 'h' [-Wunused-variable]
   22 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |                           ^
divide.cpp:22:29: warning: unused variable 'w' [-Wunused-variable]
   22 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |                             ^
divide.cpp:22:31: warning: unused variable 'c' [-Wunused-variable]
   22 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |                               ^
divide.cpp:22:35: warning: unused variable 'sum' [-Wunused-variable]
   22 |     ll n,m,k,i,j,l,r,i1,b,h,w,c=0,sum=0,ans=0,mx=-1,mn=inf;
      |                                   ^~~
divide.cpp:22:41: warning: unused variable 'ans' [-Wunused-variable]
   22 |     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 2 ms 4180 KB Output is correct
2 Incorrect 2 ms 4180 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Incorrect 2 ms 4180 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Incorrect 2 ms 4180 KB Output isn't correct
3 Halted 0 ms 0 KB -