It is a holiday season, and Koala is decorating his house with cool lights! He owns n lights, all of which flash periodically.

After taking a quick glance at them, Koala realizes that each of his lights can be described with two parameters ai and bi. Light with parameters ai and bi will toggle (on to off, or off to on) every ai seconds starting from the bi-th second. In other words, it will toggle at the moments bi, bi+ai, bi+2⋅ai and so on.

You know for each light whether it's initially on or off and its corresponding parameters ai and bi. Koala is wondering what is the maximum number of lights that will ever be on at the same time. So you need to find that out.

Here is a graphic for the first example.

Input

The first line contains a single integer n (1≤n≤100), the number of lights.

The next line contains a string s of n characters. The ii-th character is "1", if the i-th lamp is initially on. Otherwise, i-th character is "0".

The i-th of the following n lines contains two integers ai and bi (1≤ai,bi≤5)  — the parameters of the i-th light.

Output

Print a single integer — the maximum number of lights that will ever be on at the same time.

Examples
input
3
101
3 3
3 2
3 1
output
2
input
4
1111
3 4
5 2
3 1
3 2
output
4
input
6
011100
5 3
5 5
2 4
3 5
4 2
1 5
output
6
Note

For first example, the lamps' states are shown in the picture above. The largest number of simultaneously on lamps is 2 (e.g. at the moment 2).

In the second example, all lights are initially on. So the answer is 4.

解释题意:有n盏灯,1代表开0代表关,初始状态已给出,每盏灯有a和b两个属性,bs之后灯切换一次状态,之后每a秒切换一次状态。求最多同时亮几盏灯。

不难想到我们可以模拟所有的状态而所有状态的周期最多是2*3*4*5+5种。保险起见可以多跑几次

#include <bits/stdc++.h>
using namespace std;
bool a[];
int l[];
int r[];
int c[];
int f[];
int main()
{
int n;
cin>>n;
string str;
cin>>str;
for(int i=;i<str.size();++i)
{
if(str[i]=='')
{
a[i+]=;
}
else
{
a[i+]=;
}
}
for(int i=;i<=n;++i)
{
cin>>l[i]>>r[i];
c[i]=l[i];
}
int mmax=;
int tmp=;
for(int i=;i<=n;++i)
{
if(a[i]==)
{
tmp++;
mmax=max(mmax,tmp);
}
}
for(int k=;k<=;++k)
{
int tmp=;
for(int i=;i<=n;++i)
{
if(a[i]==)
{
tmp++;
mmax=max(mmax,tmp);
}
}
for(int i=;i<=n;++i)
{
if(f[i]==&&r[i]==)
{
c[i]--;
if(c[i]==)
{
c[i]=l[i];
a[i]=!a[i];
}
}
if(r[i]>)
{
r[i]--;
if(r[i]==)
{
a[i]=!a[i];
f[i]=;
}
}
}
}
cout<<mmax;
return ;
}

CF1209B Koala and Lights的更多相关文章

  1. Codeforces Round #584 B. Koala and Lights

    链接: https://codeforces.com/contest/1209/problem/B 题意: It is a holiday season, and Koala is decoratin ...

  2. Codeforces Round #584

    传送门 A. Paint the Numbers 签到. Code #include <bits/stdc++.h> using namespace std; typedef long l ...

  3. Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)

    怎么老是垫底啊. 不高兴. 似乎 A 掉一道题总比别人慢一些. A. Paint the Numbers 贪心,从小到大枚举,如果没有被涂色,就新增一个颜色把自己和倍数都涂上. #include< ...

  4. jQuery可自动播放动画焦点图插件Koala

    Koala是一款简单而实用的jQuery焦点图幻灯片插件,焦点图不仅可以在播放图片的时候让图片有淡入淡出的动画效果,而且图片可以自动播放.该jQuery焦点图的每一张图片都可以设置文字描述,并浮动在图 ...

  5. Sass:初识Sass与Koala工具的使用

    一.下载Koala(找到合适的系统版本)并安装 二.先新建一个css文件夹,并在里面新建一个文本文档(.txt),将其命名为demo.scss 三.打开Koala,将css文件夹拽进来,可以修改一下输 ...

  6. koala预编译工具的使用

    Koala是一个开源的预处理语言图形编译工具,目前已支持Less.Sass.Compass与CoffeeScript. 安装Koala 在Koala官网根据你的系统平台下载对应的版本.Linux系统要 ...

  7. HDOJ 4770 Lights Against Dudely

    状压+暴力搜索 Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  8. Ubuntu下安装Koala

    1.下载koala ,官方网址 目前官方链接的到百度云上的包好像有问题,不能安装,这里分享下 https://yunpan.cn/ckAF4L3TR4kKG (提取码:179a) 2.执行 $ sud ...

  9. [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之灯光介绍Lights

    [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之灯光介绍Lights 既上一篇分享了中文字幕的摄像机介绍Cameras后,本篇分享一下第2个已完工的 ...

随机推荐

  1. Mybatis+Spring的整合练习

    一.建立数据库.建表 二.新建maven项目 三.添加依赖 <dependencies> <dependency> <groupId>junit</group ...

  2. SC.Lab3对于Factory的构建过程(from HIT)

    Factory设计模式基本就是通过传入指定的参数/或者不传入参数,通过Factory的某个方法(为了避免实例化Factory对象,一般方法为静态static),来获取一个对象.这个是Factory用的 ...

  3. Vue--爬坑

    1.路由变化页面数据不刷新问题: 出现这种情况是因为依赖路由的params参数获取写在created生命周期里面,因为相同路由二次甚至多次加载的关系 没有达到监听,退出页面再进入另一个文章页面并不会运 ...

  4. Ubuntu 16.04.4下安装apache服务

     Ubuntu 16.04.4下安装apache服务: 一.首先,准备需要的预装环境 需要c++,make,gcc,apr  apr-util  pcre.(如果后面报错缺少什么组件,可以百度搜方法. ...

  5. zabbix监控memcached服务

    zabbix监控memcached服务 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.安装并配置memcached服务 1>.使用yum方式安装memcached [ro ...

  6. 机器阅读理解(看各类QA模型与花式Attention)(转载)

    目录 简介 经典模型概述 Model 1: Attentive Reader and Impatient Reader Attentive Reader Impatient Reader Model ...

  7. 最近学习总结 Nodejs express 获取url参数,post参数的三种方式

    express获取参数有三种方法:官网实例: Checks route params (req.params), ex: /user/:id Checks query string params (r ...

  8. mysql合并结果集

  9. java格式化代码(java格式化代码工具类)

    下别人的原来链接..... 支持效果不好要想格式化好需要解析语法树   7个积分我这里免费下      转自 https://download.csdn.net/download/jkl012789/ ...

  10. 如何将dmp文件导入到Oracle

    一.概述 在将dmp文件导入到Oracle中之前,需要先创建一个orcale用户.然后使用该用户名和密码,以imp的方式将数据导入到oracle中. 二.执行步骤 1.登陆oracle数据库 a.sq ...