题意:输入n,然后输入n个数ai,再输入n个数bi,如果在1-ai中能找到两个数x,y,x和y可以相等,如果x+y=bi,答案加上x*y,否则减去1,让结果尽可能大,输出结果。
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define ll long long 5 #define maxn 100100 6 using namespace std; 7 8 int n; 9 ll a[maxn],b[maxn]; 10 11 int main() 12 { 13 while(scanf("%d",&n)!=EOF) 14 { 15 memset(a,0,sizeof(a)); 16 memset(b,0,sizeof(b)); 17 for(int i=1; i<=n; i++) 18 { 19 scanf("%lld",&a[i]); 20 } 21 for(int i=1; i<=n; i++) 22 { 23 scanf("%lld",&b[i]); 24 } 25 ll ans=0; 26 for(int i=1; i<=n; i++) 27 { 28 if(b[i]==1) 29 { 30 ans--; 31 continue; 32 } 33 if(b[i]-a[i]>a[i]) 34 { 35 ans--; 36 continue; 37 } 38 if(b[i]%2==0) 39 ans+=(ll)((ll)(b[i]/2)*(ll)(b[i]/2)); 40 else 41 ans+=(ll)((ll)(b[i]/2)*(ll)(b[i]/2+1)); 42 } 43 printf("%lld\n",ans); 44 } 45 return 0; 46 }
时间: 2024-11-05 06:27:09