QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#428035 | #8768. Arrested Development | ucup-team3591# | WA | 1ms | 5740kb | C++14 | 901b | 2024-06-01 17:04:38 | 2024-06-01 17:04:41 |
Judging History
answer
//Man always remember love because of romance only!
#include<bits/stdc++.h>
using namespace std;
inline int read(){
int X=0,w=0; char ch=0;
while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
return w?-X:X;
}
inline void write(int x){
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
int f[2][5000001];
int a[51],b[51];
int main(){
int n=read();
for(int i=1;i<=n;i++) a[i]=read(),b[i]=read();
int sum=0;
for(int x=0;x<a[1];x++)f[1][x]=b[1];
f[1][a[1]]=0;
sum=a[1];
int res=1e9;
for(int k=2;k<=n;k++){
int op=k&1;
sum+=a[k];
for(int x=0;x<=sum;x++){
if(x-a[k]<0) f[op][x]=f[op^1][x]+b[k];
else f[op][x]=min(f[op^1][x-a[k]],f[op^1][x]+b[k]);
if(k==n){
int val=max(x,f[op][x]);
if(val<res)res=val;
}
}
}
write(res);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5668kb
input:
4 100 1 1 90 1 20 1 20
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 5592kb
input:
2 314 1 592 6
output:
7
result:
ok single line: '7'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 5740kb
input:
1 1 1
output:
1000000000
result:
wrong answer 1st lines differ - expected: '1', found: '1000000000'