QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#40769 | #3998. The Profiteer | ExplodingKonjac | WA | 3ms | 9792kb | C++17 | 5.1kb | 2022-07-26 15:53:34 | 2022-07-26 15:53:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define OPENIOBUF
namespace FastIO
{
class FastIOBase
{
protected:
#ifdef OPENIOBUF
static const int BUFSIZE=1<<22;
char buf[BUFSIZE+1];
int buf_p=0;
#endif
FILE *target;
public:
#ifdef OPENIOBUF
virtual void flush()=0;
#endif
FastIOBase(FILE *f): target(f){}
~FastIOBase()=default;
};
class FastOutput: public FastIOBase
{
#ifdef OPENIOBUF
public:
inline void flush()
{ fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
protected:
inline void __putc(char x)
{
#ifdef OPENIOBUF
if(buf[buf_p++]=x,buf_p==BUFSIZE)flush();
#else
putc(x,target);
#endif
}
template<typename T>
inline void __write(T x)
{
char stk[256],*top=stk;
if(x<0) return __putc('-'),__write(-x);
do *(top++)=x%10,x/=10; while(x);
for(;top!=stk;__putc(*(--top)+'0'));
}
public:
FastOutput(FILE *f=stdout): FastIOBase(f){}
#ifdef OPENIOBUF
~FastOutput(){ flush(); }
#endif
template<typename ...T>
inline void writesp(const T &...x)
{ initializer_list<int>{(this->operator<<(x),__putc(' '),0)...}; }
template<typename ...T>
inline void writeln(const T &...x)
{ initializer_list<int>{(this->operator<<(x),__putc('\n'),0)...}; }
inline FastOutput &operator <<(char x)
{ return __putc(x),*this; }
inline FastOutput &operator <<(const char *s)
{ for(;*s;__putc(*(s++)));return *this; }
inline FastOutput &operator <<(const string &s)
{ return (*this)<<s.c_str(); }
template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
inline FastOutput &operator <<(const T &x)
{ return __write(x),*this; }
}qout;
class FastInput: public FastIOBase
{
#ifdef OPENIOBUF
public:
inline void flush()
{ buf[fread(buf,1,BUFSIZE,target)]='\0',buf_p=0; }
#endif
protected:
inline char __getc()
{
#ifdef OPENIOBUF
if(buf_p==BUFSIZE) flush();
return buf[buf_p++];
#else
return getc(target);
#endif
}
public:
#ifdef OPENIOBUF
FastInput(FILE *f=stdin): FastIOBase(f){ buf_p=BUFSIZE; }
#else
FastInput(FILE *f=stdin): FastIOBase(f){}
#endif
inline char getchar() { return __getc(); }
template<typename ...T>
inline void read(T &...x)
{ initializer_list<int>{(this->operator>>(x),0)...}; }
inline FastInput &operator >>(char &x)
{ while(isspace(x=__getc()));return *this; }
template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
inline FastInput &operator >>(T &x)
{
static char ch,sym;x=sym=0;
while(isspace(ch=__getc()));
if(ch=='-') sym=1,ch=__getc();
for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=__getc());
return sym?x=-x:x,*this;
}
inline FastInput &operator >>(char *s)
{
while(isspace(*s=__getc()));
for(;!isspace(*s) && *s && ~*s;*(++s)=__getc());
return *s='\0',*this;
}
inline FastInput &operator >>(string &s)
{
char str_buf[(1<<8)+1],*p=str_buf;
char *const buf_end=str_buf+(1<<8);
while(isspace(*p=__getc()));
for(s.clear(),p++;;p=str_buf)
{
for(;p!=buf_end && !isspace(*p=__getc()) && *p && ~*p;p++);
*p='\0',s.append(str_buf);
if(p!=buf_end) break;
}
return *this;
}
}qin;
}
using namespace FastIO;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#else
#define FILEIO(file)
#endif
int n,m,v[200005],a[200005],b[200005],dp[200005];
LL E,ans;
class Backpack
{
private:
int siz;
vector<LL> f;
public:
Backpack()=default;
Backpack(int _s): siz(_s),f(_s+1){}
inline void init(int s)
{ siz=s,f.resize(s+1),f.assign(s+1,0); }
inline void add(int c,int v)
{ for(int i=siz;i>=c;i--) f[i]=max(f[i],f[i-c]+v); }
inline LL getsum()const
{ return accumulate(f.begin(),f.end(),0ll); }
inline LL operator [](int i)const
{ return f[i]; }
};
int findR(int l,int r,Backpack now)
{
if(l==r) return l;
int mid=(l+r)>>1;
Backpack old=now;
for(int i=l;i<=mid;i++) now.add(b[i],v[i]);
for(int i=r;i>mid;i--) now.add(a[i],v[i]);
if(now.getsum()<=E)
{
for(int i=r;i>mid;i--) old.add(a[i],v[i]);
return findR(l,mid,old);
}
else
{
for(int i=l;i<=mid;i++) old.add(b[i],v[i]);
return findR(mid+1,r,old);
}
}
void solve(int l,int r,int L,int R,Backpack now)
{
if(l>r) return;
int mid=(l+r)>>1,MID,ql=max(L,mid);
Backpack old(now);
for(int i=l;i<mid;i++) now.add(a[i],v[i]);
for(int i=mid;i<=min(r,ql-1);i++) now.add(b[i],v[i]);
MID=dp[mid]=findR(ql,R,now);
now=old;
for(int i=mid;i<=min(r,L-1);i++) now.add(b[i],v[i]);
for(int i=MID+1;i<=R;i++) now.add(a[i],v[i]);
solve(l,mid-1,L,MID,now);
now=old;
for(int i=l;i<=mid;i++) now.add(a[i],v[i]);
for(int i=max(r+1,L);i<MID;i++) now.add(b[i],v[i]);
solve(mid+1,r,MID,R,now);
}
int main()
{
qin>>n>>m>>E,E*=m;
for(int i=1;i<=n;i++) qin>>v[i]>>a[i]>>b[i];
solve(1,n,1,n+1,Backpack(m));
for(int i=1;i<=n;i++) ans+=(n-dp[i]+1);
Backpack now(m);
for(int i=1;i<=n;i++) now.add(b[i],v[i]);
qout<<now.getsum()<<'\n';
qout<<ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 9792kb
input:
4 5 3 3 2 4 1 2 3 2 1 2 3 1 3
output:
13 1
result:
wrong answer 1st lines differ - expected: '1', found: '13'