#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin>>n;
vector<pair<int, int>> v(n);
for(int i = 0;i<n;i++){
scanf("%d",&v[i].first);
}
int l = 0;
for(int i = 0;i<n;i++){
scanf("%d",&v[i].second);
l+=v[i].second;
}
sort(v.begin(), v.end());
vector<int> dp(l+10,0);
int sum = 0;
int ans = 0;
for(int i = 0;i<n;i++){
for(int j = sum;j>=0;j--){
if(v[i].second*7>=j){
dp[j+v[i].second] = max(dp[j+v[i].second],dp[j]+1);
}
ans = max(ans,dp[j+v[i].second]);
}
sum+=v[i].second;
}
cout<<ans<<endl;
}
第四题ac
第三题 from collections import defaultdict
import heapq
class Node(object):
def __init__(self,time,l,index):
self.time = time
self.l = l
self.index = index
def __lt__(self, other):
if self.time < other.time:
return True
elif self.time == other.time:
return self.index < other.index
else:
return False
N,M = map(int, input().split())
times = list(map(int, input().split()))
d = defaultdict(set)
l = []
#heapq.heapify(l)
for i in range(M):
tmp = list(map(int, input().split()))
for e in tmp[:-1]:
d[tmp[-1]].add(e)
for i in range(N):
#print(times[i], d[i+1],i+1)
heapq.heappush(l,Node(times[i], d[i+1], i+1))
res = []
while len(l) > 0:
tmp = []
node = None
while len(l) > 0:
node = heapq.heappop(l)
if len(node.l) > 0:
tmp.append(node)
else:
res.append(node.index)
break
for e in tmp:
heapq.heappush(l, e)
if node != None:
for i in range(len(l)):
if node.index in l[i].l:
l[i].l.remove(node.index)
for e in res:
print(e, end=" ")
第二题 from collections import defaultdict
words = input().split()
N = len(words)
d = defaultdict(int)
head = defaultdict(set)
for e in words:
head[e[0]].add(e[-1])
tmp = e[0] + e[-1]
d[tmp] += 1
res = False
def fun(startC, word, num):
global res
if num == 0:
res = True
return
if res == True:
return
for c in head[word[1]]:
if num == 1 and c != startC:
continue
tmp = word[1] + c
if d[tmp] > 0:
d[tmp] -= 1
fun(startC, tmp, num - 1)
d[tmp] += 1
tmp = words[0][0] + words[0][-1]
d[tmp] -= 1
fun(words[0][0],tmp,N-1)
if res:
print("true")
else:
print("false")
我也贴一下自己的代码吧~第一题 A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(float("inf"))
A.insert(0,-float("inf"))
index = 1
for i in range(1,len(A)):
if A[i] <= A[i-1]:
index = i
break
res = -float("inf")
for i in range(len(B)):
if B[i] < A[index+1] and res < B[i] and B[i] > A[index-1]:
res = B[i]
if res == -float("inf"):
index -= 1
for i in range(len(B)):
if B[i] < A[index + 1] and res < B[i] and B[i] > A[index - 1]:
res = B[i]
if res == -float("inf"):
print("NO")
else:
A[index] = res
for e in range(1, len(A) - 1):
print(A[e], end=" ")
else:
A[index] = res
for e in range(1,len(A)-1):
print(A[e],end=" ")