Skip to content

Commit bae5ad0

Browse files
committed
april lunchtime codechef
1 parent f07edeb commit bae5ad0

File tree

4 files changed

+624
-0
lines changed

4 files changed

+624
-0
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
Institute: National Institute of Technology, Uttarakhand
5+
*/
6+
#include <bits/stdc++.h>
7+
#include <ext/pb_ds/assoc_container.hpp>
8+
#include <ext/pb_ds/tree_policy.hpp>
9+
using namespace std;
10+
using namespace __gnu_pbds;
11+
typedef long long ll ;
12+
typedef unsigned long long ull;
13+
typedef vector<ll> vl;
14+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
15+
/* Abbrevations */
16+
#define ff first
17+
#define ss second
18+
#define mp make_pair
19+
#define line cout<<endl;
20+
#define pb push_back
21+
#define Endl "\n"
22+
// loops
23+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
24+
// Some print
25+
#define no cout<<"No"<<endl;
26+
#define yes cout<<"Yes"<<endl;
27+
// sort
28+
#define all(V) (V).begin(),(V).end()
29+
#define srt(V) sort(all(V))
30+
#define srtGreat(V) sort(all(V),greater<ll>())
31+
// some extra
32+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
33+
#define precision(x) cout<<fixed<<setprecision(x);
34+
#define sz(V) ll(V.size())
35+
// template
36+
template <typename T>
37+
T mymax(T x,T y)
38+
{
39+
return (x>y)?x:y;
40+
}
41+
// function
42+
ll power(ll x,ll y,ll mod)
43+
{
44+
ll res=1;
45+
// x=x%mod;
46+
while(y>0)
47+
{
48+
if(y%2==1)
49+
{
50+
res*=x;
51+
// res=res%mod;
52+
}
53+
y/=2; x*=x; // x=x%mod;
54+
}
55+
return res;
56+
}
57+
ll str_to_num(string s)
58+
{
59+
return stoi(s);
60+
}
61+
62+
string num_to_str(ll num)
63+
{
64+
return to_string(num);
65+
}
66+
// datatype definination
67+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
68+
class Point
69+
{
70+
public:
71+
ll x;
72+
ll y;
73+
ll z;
74+
ll getsum()
75+
{
76+
return x+y+z;
77+
}
78+
};
79+
/* ascii value
80+
A=65,Z=90,a=97,z=122
81+
*/
82+
/* --------------------MAIN PROGRAM----------------------------*/
83+
// to run ctrl+b
84+
const ll INF=LONG_MAX;
85+
const ll mod1=1e9+7;
86+
const ll mod2=998244353;
87+
88+
89+
// Techniques
90+
// divide into cases, brute force, pattern finding
91+
// sort, greedy, binary search, two pointer
92+
// transform into graph
93+
94+
ll solve()
95+
{
96+
ll n;
97+
cin>>n;
98+
vl v(n);
99+
ll sum=0;
100+
for(ll i=0;i<n;i++){
101+
cin>>v[i];
102+
sum+=v[i];
103+
sum%=mod1;
104+
if(sum<0)
105+
sum+=mod1;
106+
}
107+
ll q;
108+
cin>>q;
109+
while(q--){
110+
ll temp;
111+
cin>>temp;
112+
sum*=2LL;
113+
sum%=mod1;
114+
if(sum<0)
115+
sum+=mod1;
116+
cout<<sum<<endl;
117+
}
118+
return 0;
119+
}
120+
121+
int main()
122+
{
123+
speed;
124+
/* #ifndef ONLINE_JUDGE
125+
freopen("input.txt","r",stdin);
126+
freopen("output.txt","w",stdout);
127+
#endif */
128+
ll TestCase=1;
129+
// cin>>TestCase;
130+
while(TestCase--)
131+
{
132+
solve();
133+
}
134+
}
135+
/* -----------------END OF PROGRAM --------------------*/
136+
/*
137+
* stuff you should look before submission
138+
* constraint and time limit
139+
* int overflow
140+
* special test case (n=0||n=1||n=2)
141+
* don't get stuck on one approach if you get wrong answer
142+
*/
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
Institute: National Institute of Technology, Uttarakhand
5+
*/
6+
#include <bits/stdc++.h>
7+
#include <ext/pb_ds/assoc_container.hpp>
8+
#include <ext/pb_ds/tree_policy.hpp>
9+
using namespace std;
10+
using namespace __gnu_pbds;
11+
typedef long long ll ;
12+
typedef unsigned long long ull;
13+
typedef vector<ll> vl;
14+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
15+
/* Abbrevations */
16+
#define ff first
17+
#define ss second
18+
#define mp make_pair
19+
#define line cout<<endl;
20+
#define pb push_back
21+
#define Endl "\n"
22+
// loops
23+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
24+
// Some print
25+
#define no cout<<"NO"<<endl;
26+
#define yes cout<<"YES"<<endl;
27+
// sort
28+
#define all(V) (V).begin(),(V).end()
29+
#define srt(V) sort(all(V))
30+
#define srtGreat(V) sort(all(V),greater<ll>())
31+
// some extra
32+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
33+
#define precision(x) cout<<fixed<<setprecision(x);
34+
#define sz(V) ll(V.size())
35+
// template
36+
template <typename T>
37+
T mymax(T x,T y)
38+
{
39+
return (x>y)?x:y;
40+
}
41+
// function
42+
ll power(ll x,ll y,ll mod)
43+
{
44+
ll res=1;
45+
// x=x%mod;
46+
while(y>0)
47+
{
48+
if(y%2==1)
49+
{
50+
res*=x;
51+
// res=res%mod;
52+
}
53+
y/=2; x*=x; // x=x%mod;
54+
}
55+
return res;
56+
}
57+
ll str_to_num(string s)
58+
{
59+
stringstream pk(s);
60+
ll num;
61+
pk>>num;
62+
return num;
63+
}
64+
65+
string num_to_str(ll num)
66+
{
67+
return to_string(num);
68+
}
69+
// datatype definination
70+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
71+
class Point
72+
{
73+
public:
74+
ll x;
75+
ll y;
76+
ll z;
77+
ll getsum()
78+
{
79+
return x+y+z;
80+
}
81+
};
82+
/* ascii value
83+
A=65,Z=90,a=97,z=122
84+
*/
85+
/* --------------------MAIN PROGRAM----------------------------*/
86+
// to run ctrl+b
87+
const ll INF=LONG_MAX;
88+
const ll mod1=1e9+7;
89+
const ll mod2=998244353;
90+
91+
92+
// Techniques
93+
// divide into cases, brute force, pattern finding
94+
// sort, greedy, binary search, two pointer
95+
// transform into graph
96+
97+
ll solve()
98+
{
99+
ll n,w,wr;
100+
cin>>n>>w>>wr;
101+
vl v(n);
102+
forin(v,n);
103+
map<ll,ll> m;
104+
for(ll i=0;i<n;i++){
105+
m[v[i]]++;
106+
}
107+
ll wieght=0;
108+
for(auto x:m){
109+
ll temp=x.ss/2;
110+
wieght+=temp*x.ff;
111+
if(((wieght*2)+wr)>=w){
112+
yes
113+
return 0;
114+
}
115+
}
116+
no
117+
return 0;
118+
}
119+
120+
int main()
121+
{
122+
speed;
123+
/* #ifndef ONLINE_JUDGE
124+
freopen("input.txt","r",stdin);
125+
freopen("output.txt","w",stdout);
126+
#endif */
127+
ll TestCase=1;
128+
cin>>TestCase;
129+
while(TestCase--)
130+
{
131+
solve();
132+
}
133+
}
134+
/* -----------------END OF PROGRAM --------------------*/
135+
/*
136+
* stuff you should look before submission
137+
* constraint and time limit
138+
* int overflow
139+
* special test case (n=0||n=1||n=2)
140+
* don't get stuck on one approach if you get wrong answer
141+
*/

0 commit comments

Comments
 (0)