标签:pen for ace smart max plm include new details
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 13578 | Accepted: 5503 |
Description
Input
Output
Sample Input
5 -5 7 8 -6 6 -3 2 1 -8 -5
Sample Output
8
Hint
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<cstdlib> 5 #include<cmath> 6 #include<algorithm> 7 using namespace std; 8 int n; 9 int f[200005]; 10 int a[101],b[101]; 11 int main() 12 { 13 scanf("%d",&n); 14 for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]); 15 memset(f,-5,sizeof(f)); 16 int ans=0,m1=0,m2=0; 17 f[100000]=0; 18 for(int i=1;i<=n;i++) 19 { 20 if(a[i]>0) 21 for(int j=200000;j>=a[i];j--) 22 { 23 f[j]=max(f[j],f[j-a[i]]+b[i]); 24 if(j-100000>=0&&f[j]>=0&&j-100000+f[j]>ans)ans=j-100000+f[j]; 25 } 26 if(a[i]<0) 27 for(int j=0;j<=200000+a[i];j++) 28 { 29 f[j]=max(f[j],f[j-a[i]]+b[i]); 30 if(j-100000>=0&&f[j]>=0&&j-100000+f[j]>ans)ans=j-100000+f[j]; 31 } 32 } 33 cout<<ans; 34 }
标签:pen for ace smart max plm include new details
原文地址:http://www.cnblogs.com/wls001/p/7112672.html