-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpizza.cpp
More file actions
83 lines (70 loc) · 1.37 KB
/
pizza.cpp
File metadata and controls
83 lines (70 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <bits/stdc++.h>
#include<fstream>
using namespace std;
vector<int> sum_p(int m,int n,vector<int> s){
vector<int> curr;
vector<int> sol;
int sum=-1;
int c=0;
for(int i=n-1;i>=0;i--){
curr.clear();
c=s[i];
curr.push_back(i);
if(c>m) continue;
if(c==m) {
sol=curr;
curr.clear();
return sol;
}
for(int j=n-1;j>=0 && i!=j;j--){
c+=s[j];
if(c>m){
c-=s[j];
continue;
}
curr.push_back(j);
if(c==m){
sol=curr;
curr.clear();
return sol;
}
}
if(c>sum){
sum=c;
sol=curr;
curr.clear();
}
}
return sol;
}
void printsol(vector<int> sol){
sort(sol.begin(),sol.end());
ofstream ans;
ans.open("E_also_big.out");
ans<<sol.size()<<endl;
for(int i=0;i<sol.size();i++){
ans<<sol[i]<<" ";
}
ans<<endl;
ans.close();
return;
}
int main()
{
ifstream ex;
int m,n;
ex.open("e_also_big.in");
ex>>m>>n;
vector<int> sl;
for(int i=0;i<n;i++)
{
int a;
ex>>a;
sl.push_back(a);
}
ex.close();
vector<int> sol;
sol= sum_p(m,n,sl);
printsol(sol);
return 0;
}