From 80860dc70ba0fab85105fd870749261f1fc86115 Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Mon, 17 Nov 2025 00:16:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0P14507.cpp=E8=A7=A3?= =?UTF-8?q?=E9=A2=98=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实现一个处理特定输入格式并计算结果的算法 --- src/11/16/P14507.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/11/16/P14507.cpp diff --git a/src/11/16/P14507.cpp b/src/11/16/P14507.cpp new file mode 100644 index 0000000..68d01ec --- /dev/null +++ b/src/11/16/P14507.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include +#include +#include +#include +using ll = int64_t; +#define sl static inline + +ll n,q; +std::map m; + +sl void solve(){ + std::cin>>n>>q; + bool isnotok=false; + m.clear(); + ll last=-1; + for(ll i=1;i<=n;i++){ + ll a,b; + std::cin>>a>>b; + if(isnotok)continue; + if(a!=last+1){ + isnotok=true; + continue; + } + last=a; + m[a]+=b; + } + while(q--){ + ll nq; + std::cin>>nq; + printf("getq = %lld\n",nq); + auto nm=m; + ll ans=0; + while(nm.size()){ + auto pm = nm.lower_bound(nq); + if(nq==0||pm->first>nq)break; + ans++; + ll min=1e9+7; + if(pm!=nm.end())pm++; + for(auto wp=nm.begin();wp!=pm;wp++){ + min=std::min(min,wp->second); + } + printf("got min=%lld, pm->first=%lld\n",min,pm->first); + ll maxget = nq/pm->first; + printf("maxget=%lld\n",maxget); + ll get=std::min(maxget,min); + printf("get=%lld\n",get); + bool isrm=false; + std::vector rm; + for(auto wp=nm.begin();wp!=pm;wp++){ + if(isrm){ + rm.push_back(wp); + continue; + } + wp->second-=get; + if(wp->second==0){ + isrm=true; + rm.push_back(wp); + } + } + for(auto i:rm){ + nm.erase(i); + } + } + std::cout<<(ans==0?-1:ans)<<"\n"; + } +} + +int main(){ + std::iostream::sync_with_stdio(false); + std::cin.tie(nullptr); + + ll T; + std::cin>>T; + while(T--){ + solve(); + } +} \ No newline at end of file