Submission #1041204

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
10412042024-08-01 17:41:58Antony2357111317Knapsack (NOI18_knapsack)C++11
100 / 100
89 ms5572 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct item {
ll weight, worth, cnt;
};
bool comp(item i1, item i2){
if(i1.weight == i2.weight){
return (i1.worth > i2.worth);
}
return (i1.weight < i2.weight);
}
int main() {
ll S, N;
cin >> S >> N;
vector<item> items;
for(ll i = 0; i < N; i++){
ll wei, wor, cnt;
cin >> wor >> wei >> cnt;
items.push_back({wei, wor, cnt});
}
sort(items.begin(), items.end(), comp);
vector<item> new_item;
map<ll,ll> myMap;
for(item item: items){
if(myMap[item.weight] * item.weight > S){
continue;
}
myMap[item.weight] += item.cnt;
new_item.push_back(item);
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:38:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<item>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |   for(ll i = 1; i <= items.size(); i++){
      |                 ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...