8 条题解

  • 2
    @ 2023-5-1 11:57:50
    using namespace std;
    long long a[1000005],n,m,maxn;
    bool check(int x){
    	int sum=0,cnt=1;
    	for(int i=1;i<=n;i++){
    		if(sum+a[i]<=x) sum+=a[i];
    		else{
    			cnt++;
    			sum=a[i];
    		}
    	}
    	return cnt<=m;
    }
    int main(){
    	cin>>n>>m;
    	for(int i=1;i<=n;i++){
    		cin>>a[i];
    		maxn=max(maxn,a[i]);
    	}
    	int l=maxn, r=1000000000;
    	while(l<r){
    		int mid=(l+r)>>1;
    		if(check(mid))r=mid;
    		else l=mid+1;
    	}
    	cout<<l;
    }
    
  • 1
    @ 2023-5-2 18:28:38
    #include <bits/stdc++.h>
    using namespace std;
    long long a[1000005],n,m,maxn;
    bool check(int x){
    	int sum=0,cnt=1;
    	for(int i=1;i<=n;i++){
    		if(sum+a[i]<=x) sum+=a[i];
    		else{
    			cnt++;
    			sum=a[i];
    		}
    	}
    	return cnt<=m;
    }
    int main(){
    	cin>>n>>m;
    	for(int i=1;i<=n;i++){
    		cin>>a[i];
    		maxn=max(maxn,a[i]);
    	}
    	int l=maxn, r=1000000000;
    	while(l<r){
    		int mid=(l+r)>>1;
    		if(check(mid))r=mid;
    		else l=mid+1;
    	}
    	cout<<l;
    }
    
    
    • 0
      @ 2023-5-28 10:02:07

      #include<bits/stdc++.h> using namespace std; #define ll long long const int N=1e5+10; const int INF=0x3f3f3f3f; int n,m,a[N],l,r,ans; bool check(int mid){ int sum=0,num=1; for(int i=1;i<=n;i++){ if(sum+a[i]<=mid){ sum+=a[i]; }else{ num++; sum=a[i]; } } return num<=m; } signed main(){ cin>>n>>m; for(int i=1;i<=n;i++){ cin>>a[i]; l=max(l,a[i]); r+=a[i]; } while(l<=r){ int mid=(l+r)/2; if(check(mid)){ ans=mid; r=mid-1; }else{ l=mid+1; } } cout<<ans; return 0; }

      • 0
        @ 2023-5-1 12:00:37
        #include <bits/stdc++.h>
        using namespace std;
        long long a[1000005],n,m,maxn;
        bool check(int x){
        	int sum=0,cnt=1;
        	for(int i=1;i<=n;i++){
        		if(sum+a[i]<=x) sum+=a[i];
        		else{
        			cnt++;
        			sum=a[i];
        		}
        	}
        	return cnt<=m;
        }
        int main(){
        	cin>>n>>m;
        	for(int i=1;i<=n;i++){
        		cin>>a[i];
        		maxn=max(maxn,a[i]);
        	}
        	int l=maxn, r=1000000000;
        	while(l<r){
        		int mid=(l+r)>>1;
        		if(check(mid))r=mid;
        		else l=mid+1;
        	}
        	cout<<l;
        }
        
        • 0
          @ 2023-5-1 11:59:33
          #include<algorithm>
          using namespace std;
          int a[1000005],n,m,maxn;  
          bool check(int x){
          	int sum=0,cnt =1;
          	for (int i=1; i<=n; i++){
          		if (sum+a[i]<=x){
          			sum +=a[i];
          		}
          		else{
          			cnt++;
          			sum=a[i];
          		}
          	
          	}
          	return cnt <= m;
          }                                                
          int main(){
          	cin >>n >> m;
          	for (int i=1; i<=n; i++){
          		cin >> a[i];
          		maxn=max(maxn,a[i]);
          	}
          	int l=maxn,r=1000000000;
          	while(l<r){
          		int mid=(l+r)>>1;
          		if (check(mid)) {
          			r=mid;
          		}
          		else {
          			l=mid+1;
          		}
          	}
          	cout << l;
          	return 0;
          }
          
          • -1
            @ 2022-10-18 22:32:30
            #include <iostream>
            #include <string.h>
            using namespace std;
            const int N = 1e5 + 10;
            const int INF = 0x3f3f3f3f;
            long long n , k;
            int a[N];
            bool cheak(int x)
            {
            	int ans = 1 , sum = 0;
            	for(int i = 1 ; i <= n ; i++)
            	{
            		sum += a[i];
            		if(sum > x)
            		{
            			ans++;
            			sum = a[i];
            		}
            	}
            	return ans <=  k;
            }
            int main()
            {
            	cin >> n >> k;
            	int l , r;
            	l = 0 , r = 0;
            	for(int i = 1 ; i <= n ; i++)
            	{
            		cin >>a[i];
            		r += a[i];
            		l = max(l , a[i]);
            	}
            	while(l < r)
            	{
            		int mid = l + r >> 1;
            		if(cheak(mid))
            			r = mid;
            		else
            			l = mid + 1;
            	}
            	cout << r << endl;
            	return 0;
            }
            
            • -1
              @ 2022-5-14 12:00:51
              #include <queue>
              #include <math.h>
              #include <stack>
              #include <stdio.h>
              #include <iostream>
              #include <vector>
              #include <iomanip>
              #include <string.h>
              #include <algorithm>
              using namespace std;
              #define LL long long
              const int N = 1e6 + 10;
              const int INF = 0x3f3f3f3f;
              int n,m;
              int maxx=0;
              int a[N];
              int minn=0;
              bool cheak(int x)
              {
              	int ans=0;
              	int cnt=1;
              	for(int i=0;i<n;i++)
              	{
              		if(ans+a[i]<=x)
              			ans+=a[i];
              		else
              		{
              			ans=a[i];
              			cnt++;
              		}
              	}
              	return cnt<=m;
              	
              }
              int find()
              {
              	int l=minn,r=maxx;
              	while(l<r)
              	{
              		int mid=l+r>>1;
              		if(cheak(mid))
              			r=mid;
              		else
              			l=mid+1;
              	}
              	return r;
              }
              int main ()
              {
              	cin >> n >> m;
              	for(int i=0;i<n;i++)
              	{
              		cin >> a[i];
              		maxx+=a[i];
              		minn=max(a[i],minn);
              	}
              	cout << find()<<endl;
              	return 0;
              }
              
              
              • -1
                @ 2021-12-25 20:51:28
                #include <queue>
                #include <math.h>
                #include <stack>
                #include <stdio.h>
                #include <iostream>
                #include <vector>
                #include <iomanip>
                #include <string.h>
                #include <algorithm>
                using namespace std;
                #define LL long long
                const int N = 1e6 + 10;
                const int INF = 0x3f3f3f3f;
                int n,m,x[N],sum=0,max1=0;
                int aa(int sum1)
                {
                    int num=1;
                    int temp=0;
                    for(int i=0;i<n;i++)
                    {
                        temp+=x[i];
                        if(temp>sum1)
                        {
                            num++;
                            temp=x[i];
                        }
                    }
                    if(num>m)
                		return 1;
                    return 0;
                }
                int main()
                {
                    cin>>n>>m;
                    for(int i=0;i<n;i++)
                    {
                        cin>>x[i];
                        sum+=x[i];
                        if(x[i]>max1)max1=x[i];
                    }
                    int l=max1,r=sum;
                    while(l<r)
                    {
                        int mid=(l+r)/2;
                        if(aa(mid))l=mid+1;
                        else r=mid;
                    }
                    cout<<r<<endl;
                    return 0;
                
                }
                • 1

                信息

                ID
                360
                时间
                1000ms
                内存
                512MiB
                难度
                6
                标签
                递交数
                314
                已通过
                97
                上传者