2 solutions

  • 2
    @ 2024-5-22 13:54:42
    #include<bits/stdc++.h>
    using namespace std;
    int n;
    int m[110],d[110],t[110];
    int main(){
        cin>>n;
        for(int i=1;i<=n;i++){
        	cin >> m[i];
    	}
        for(int i=1;i<=n;i++){
        	cin>>d[i];
    	} 
        for(int i=2;i<=n;i++){
            cin>>t[i];
            t[i]+=t[i-1];
        }
        int time;
        cin>>time;
        int maxn=0;
        for(int k=1;k<=n;k++){
            int fishtime=time-t[k]; 
            priority_queue<pair<int,int>>q; 
            for(int i=1;i<=k;i++){
                q.push({m[i],i});
    		}
            int fish=0; 
            while(q.size()&&fishtime>0){
                fish+=q.top().first;
                fishtime--;
                if (q.top().first-d[q.top().second]>0) {
    				q.push({q.top().first-d[q.top().second],q.top().second});
            	}
            	q.pop();
    		}		
            maxn=max(maxn,fish);
        }
        cout<<maxn;
        return 0;
    }
    
    • -1
      @ 2024-6-2 16:29:48
      #include<iostream>
      #include<queue>
      using namespace std;
      int n,m[101],lss[101],t[101];
      int timee;
      
      int main()
      {
      	cin >> n;
      	for (int i=1;i<=n;i++){				//按照题意输入 
      		cin >> m[i];
      	}
      	for (int i=1;i<=n;i++){
      		cin >> lss[i];
      	}
      	for (int i=2;i<=n;i++){
      		cin >> t[i];
      		t[i]+=t[i-1];					//类似前缀和,到第i个点需花费t[i]的时间 
      	}
      	
      	int maxx=0;
      	cin >> timee;
      	priority_queue <pair<int,int> > q;
      	for (int k=1;k<=n;k++){				//用于枚举每次钓鱼的终点 
      		for (int i=1;i<=k;i++){			//将终点前的所有鱼塘入队 
      			q.push({m[i],i});
      		}
      		
      		int fish=0;					
      		for (int ft=timee-t[k];ft>0 && !q.empty();ft--){		//ft是真正可用于钓鱼的时间 
      			fish+=q.top().first;
      			if (q.top().first-lss[q.top().second]>0){			//鱼的数量递减 
      				q.push({q.top().first-lss[q.top().second],q.top().second}); 
      			}
      			q.pop();
      		}
      		maxx=max(maxx,fish);
      		while(!q.empty())q.pop();		//清空队列 
      	}
      	cout << maxx;						//输出 
      	
      }
      
      • 1

      Information

      ID
      858
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      7
      Tags
      # Submissions
      20
      Accepted
      9
      Uploaded By