建议添加标签:三分

P3745 [六省联考 2017] 期末考试

同意
by Fractured_Angel @ 2024-01-25 14:00:42


蒟蒻没看出来为什么qwq 能解释一下吗
by ShelpAm @ 2024-01-25 14:34:58


```cpp #include<bits/stdc++.h> #define I using #define AK namespace #define IOI std I AK IOI; #define int long long //#define getchar getchar_unlocked //#define putchar putchar_unlocked inline int rd(){int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;for(;isdigit(ch);ch=getchar())x=(x<<3)+(x<<1)+(ch^48);return x*f;} inline void write(int _v){if(_v<0){_v=~(_v-1);putchar('-');}if(_v>9)write(_v/10);putchar(_v%10^48);} inline void tbl(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);} const int MS=1e5+5; int n,m,t[MS],b[MS]; int A,B,C,ans; int c1(int p){ int x=0,y=0; for(int i=1;i<=m;++i){ if(b[i]<p)x+=p-b[i]; else y+=b[i]-p; }if(A<B)return min(x,y)*A+(y-min(x,y))*B; else return y*B; }int c2(int p){ int sum=0; for(int i=1;i<=n;++i)if(t[i]<p)sum+=(p-t[i])*C; return sum; }signed main(){ A=rd(),B=rd(),C=rd(),n=rd(),m=rd(); for(int i=1;i<=n;++i)t[i]=rd(); for(int i=1;i<=m;++i)b[i]=rd(); sort(t+1,t+n+1);sort(b+1,b+n+1); if(C>=1e16)cout<<c1(t[1]),exit(0); ans=1e16; int l=1,r=MS; while(r-l>2){ int m1=l+(r-l)/3,m2=r-(r-l)/3; int _1=c1(m1)+c2(m1),_2=c1(m2)+c2(m2); if(_1<_2)r=m2; else l=m1; }for(int i=l;i<=r;++i){ int x=c1(i)+c2(i); ans=min(ans,x); }cout<<ans; } ``` 算法禁赛
by Side_sdtkwxt @ 2024-02-03 17:40:35


蒟蒻是用前缀和做的QwQ ```cpp #include <bits/stdc++.h> using namespace std; const int MAXLEN = 2 * 1e5 + 5; long long a[MAXLEN], qzh[MAXLEN] = {0}, sum = 0; int n; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; qzh[i] = qzh[i - 1] + a[i]; } for (int i = 1; i <= n; i++) { sum += a[i] * (qzh[n] - qzh[i]); } cout << sum; return 0; } ```
by Change_YuAN @ 2024-04-06 19:09:33


|